Fix a regression that allowed clearly ill formed code. The diagnostic is still
authorChandler Carruth <chandlerc@gmail.com>
Tue, 31 Aug 2010 05:42:40 +0000 (05:42 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 31 Aug 2010 05:42:40 +0000 (05:42 +0000)
terrible, FIXME left to do a proper job of diagnosing this.

llvm-svn: 112581

clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/dcl.decl/dcl.init/p5.cpp [new file with mode: 0644]

index fdffa0403737351b4f5903da2da2096c3f8df8ca..4b116890fa1d475df905f35b94e3670aa11ddb19 100644 (file)
@@ -6135,6 +6135,8 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
       CXXRecord->setPOD(false);
     if (!ZeroWidth)
       CXXRecord->setEmpty(false);
+    if (T->isReferenceType())
+      CXXRecord->setHasTrivialConstructor(false);
 
     if (const RecordType *RT = EltTy->getAs<RecordType>()) {
       CXXRecordDecl* RDecl = cast<CXXRecordDecl>(RT->getDecl());
diff --git a/clang/test/CXX/dcl.decl/dcl.init/p5.cpp b/clang/test/CXX/dcl.decl/dcl.init/p5.cpp
new file mode 100644 (file)
index 0000000..b50e8d7
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// FIXME: Very incomplete!
+
+//   A program that calls for default-initialization or value-initialization of
+//   an entity of reference type is illformed. If T is a cv-qualified type, the
+//   cv-unqualified version of T is used for these definitions of
+//   zero-initialization, default-initialization, and value-initialization.
+//
+// FIXME: The diagnostics for these errors are terrible because they fall out
+// of the AST representation rather than being explicitly issued during the
+// respective initialization forms.
+struct S { // expected-error {{implicit default constructor for 'S' must explicitly initialize the reference member}} \
+           // expected-note {{candidate constructor (the implicit copy constructor) not viable}}
+  int& x; // expected-note {{declared here}}
+};
+S s; // expected-note {{implicit default constructor for 'S' first required here}}
+S f() {
+  return S(); // expected-error {{no matching constructor for initialization of 'S'}}
+}