Bug 60940 - general operations on atomic types do not work with atomic integral typedefs
Summary: general operations on atomic types do not work with atomic integral typedefs
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-04-23 13:21 UTC by Jonathan Wakely
Modified: 2015-01-17 01:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-05-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2014-04-23 13:21:47 UTC
This is rejected because the atomic operations only accept std::atomic<T> not the std::__atomic_base<T> base classes:

#ifdef __cplusplus
#include <atomic>
using namespace std;
#else
#include <stdatomic.h>
#endif

atomic_int i;

int main()
{
  atomic_store(&i, 0);
  return atomic_load(&i);
}
Comment 1 Jonathan Wakely 2014-04-23 17:07:42 UTC
Additionally, we fail to meet this requirement:

29.6.2  Templated operations on atomic types  [atomics.types.operations.templ]
The implementation shall declare but not define the function templates identified as “templated operations on atomic types” in 29.2.

We only declare those functions templates when they need to be defined, i.e. for arguments of type __atomic_base or atomic<T*>.

The declarations would need to be constrained with SFINAE to prevent them being used for types derived from __atomic_base.
Comment 2 Jonathan Wakely 2015-01-17 01:24:03 UTC
Author: redi
Date: Sat Jan 17 01:23:28 2015
New Revision: 219790

URL: https://gcc.gnu.org/viewcvs?rev=219790&root=gcc&view=rev
Log:
	PR libstdc++/60940
	* include/bits/atomic_base.h: Remove atomic integral typedefs as
	synonyms for __atomic_base<int> etc.
	* include/std/atomic: Make atomic_int a synonym for atomic<int> and
	likewise for all atomic integral types.
	* testsuite/29_atomics/atomic_integral/cons/copy_list.cc: New.
	* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error line number.

Added:
    trunk/libstdc++-v3/testsuite/29_atomics/atomic_integral/60940.cc
      - copied, changed from r219785, trunk/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/atomic_base.h
    trunk/libstdc++-v3/include/std/atomic
    trunk/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc
Comment 3 Jonathan Wakely 2015-01-17 01:24:24 UTC
Fixed for GCC 5