https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66268

            Bug ID: 66268
           Summary: struct { volatile int x; } should not be trivially
                    copyable
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: comexk at gmail dot com
  Target Milestone: ---

According to the C++14 standard, a struct containing volatile fields shouldn't
be trivially copyable.  9.6 states:

> A trivially copyable class is a class that:
> — has no non-trivial copy constructors (12.8),

and 12.8.12 states:

> A copy/move constructor for class X is trivial if it is not user-provided, 
> its parameter-type-list is equivalent to the parameter-type-list of an 
> implicit declaration, and if
[..]
> — class X has no non-static data members of volatile-qualified type, and


GCC disagrees:

#include <iostream>
#include <type_traits>

int main() {
    struct foo { volatile int x; };
    std::cout << std::is_trivially_copyable<foo>::value << std::endl;
}

/tmp % g++-5 --version    
g++-5 (Homebrew gcc5 5.1.0) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

/tmp % g++-5 -std=c++14 -o test test.cpp && ./test
1

Reply via email to