Bug 55861 - [C++11] `std::shared_future::get' is not const-qualified
Summary: [C++11] `std::shared_future::get' is not const-qualified
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-01-03 14:11 UTC by Ai Azuma
Modified: 2013-09-26 19:04 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.6.4, 4.7.3, 4.8.0
Last reconfirmed: 2013-01-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ai Azuma 2013-01-03 14:11:40 UTC
`std::shared_future<R>::get' member function is specified as const-qualified in [futures.shared_future]. However, libstdc++'s implementation is not. A testcase would be as follows;

//--------------------------------------------------
#include <future>

int f()
{
  return 42;
}

int main()
{
  std::shared_future<int> const ftr(std::async(&f));
  ftr.get(); // Line 11
}
//--------------------------------------------------

For the above testcase, GCC 4.8.0 20121230 complains as follows;

main.cpp: In function 'int main()':
main.cpp:11:11: error: passing 'const std::shared_future<int>' as 'this' argument of 'const _Res& std::shared_future<_Res>::get() [with _Res = int]' discards qualifiers [-fpermissive]
   ftr.get();
           ^
Comment 1 Jonathan Wakely 2013-01-03 14:22:05 UTC
The fix should be as simple as adding "const" to __basic_future::_M_get_result and the three shared_future::get() functions.
Comment 2 Jonathan Wakely 2013-01-19 23:43:01 UTC
Author: redi
Date: Sat Jan 19 23:42:55 2013
New Revision: 195314

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195314
Log:
	PR libstdc++/55861
	* include/std/future (_State_base::_S_check(const shared_ptr<T>&)):
	Fix return type.
	(__basic_future::_M_get_result()): Const qualify.
	(shared_future::get()): Likewise.
	* testsuite/30_threads/shared_future/members/get.cc: Use const
	objects.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/future
    trunk/libstdc++-v3/testsuite/30_threads/shared_future/members/get.cc
Comment 3 Jonathan Wakely 2013-01-19 23:44:16 UTC
fixed for 4.8
Comment 4 Jonathan Wakely 2013-09-26 19:04:07 UTC
Author: redi
Date: Thu Sep 26 19:04:04 2013
New Revision: 202956

URL: http://gcc.gnu.org/viewcvs?rev=202956&root=gcc&view=rev
Log:
	Backport from mainline

	2013-01-19  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/55861
	* include/std/future (_State_base::_S_check(const shared_ptr<T>&)):
	Fix return type.

Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/std/future