Files
clang-p2996/clang/test/CXX/dcl.decl/dcl.init/p6.cpp
Nico Weber 6a6376b17c Implement the likely resolution of core issue 253.
C++11 requires const objects to have a user-provided constructor, even for
classes without any fields. DR 253 relaxes this to say "If the implicit default
constructor initializes all subobjects, no initializer should be required."

clang is currently the only compiler that implements this C++11 rule, and e.g.
libstdc++ relies on something like DR 253 to compile in newer versions.  This
change  makes it possible to build code that says `const vector<int> v;' again
when using libstdc++5.2 and _GLIBCXX_DEBUG
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60284).

Fixes PR23381.

http://reviews.llvm.org/D16552

llvm-svn: 261297
2016-02-19 01:52:46 +00:00

29 lines
1.1 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
// FIXME: Very incomplete!
// If a program calls for the default initialization of an object of a
// const-qualified type T, T shall be a class type with a
// user-provided default constructor, except if T has no uninitialized fields.
struct MakeNonPOD { MakeNonPOD(); };
struct NoUserDefault : public MakeNonPOD { int field; };
struct HasUserDefault { HasUserDefault(); };
void test_const_default_init() {
const NoUserDefault x1; // expected-error{{default initialization of an object of const type 'const NoUserDefault' without a user-provided default constructor}}
const HasUserDefault x2;
const int x3; // expected-error{{default initialization of an object of const type 'const int'}}
}
// rdar://8501008
struct s0 { int field; };
struct s1 { static const s0 foo; };
const struct s0 s1::foo; // expected-error{{default initialization of an object of const type 'const struct s0' without a user-provided default constructor}}
template<typename T>
struct s2 {
static const s0 foo;
};
template<> const struct s0 s2<int>::foo; // okay