mercredi 4 février 2015

Clang Compile error with default initialization

Consider following example:



#include <iostream>
#include <type_traits>

struct A
{
//A() = default; // does neither compile with, nor without this line
//A(){}; // does compile with this line
int someVal{ 123 };


void foobar( int )
{
};
};


int main()
{
const A a;
std::cout << "isPOD = " << std::is_pod<A>::value << std::endl;
std::cout << "a.someVal = " <<a.someVal << std::endl;
}


See Live example


This does compile with g++ but does not compile with clang++, tried with following command: 'clang++ -std=c++11 -O0 main.cpp && ./a.out'


Compile error from clang: main.cpp:19:13: error: default initialization of an object of const type 'const A' requires a user-provided default constructor


I learned from This Stack Overflow Question, that non-POD classes get default constructor. This is even not necessary here because the variable has c++11-style default initialization


Why does this not for clang? Why does 'A() = default;' not work, too?


Aucun commentaire:

Enregistrer un commentaire