]> granicus.if.org Git - clang/commitdiff
PR31692: Don't mark a declaration as invalid if we haven't necessarily emitted a...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 23 Jan 2017 23:14:23 +0000 (23:14 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 23 Jan 2017 23:14:23 +0000 (23:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292847 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/cxx11-default-member-initializers.cpp [new file with mode: 0644]

index a70e16cce18ce6f3c9c2df4ada2add590482d4d9..f265f4c00f71b93adc0a866a701f59056ac57de3 100644 (file)
@@ -12383,9 +12383,9 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
   Diag(Loc, diag::err_in_class_initializer_not_yet_parsed)
       << OutermostClass << Field;
   Diag(Field->getLocEnd(), diag::note_in_class_initializer_not_yet_parsed);
-
-  // Don't diagnose this again.
-  Field->setInvalidDecl();
+  // Recover by marking the field invalid, unless we're in a SFINAE context.
+  if (!isSFINAEContext())
+    Field->setInvalidDecl();
   return ExprError();
 }
 
diff --git a/test/SemaCXX/cxx11-default-member-initializers.cpp b/test/SemaCXX/cxx11-default-member-initializers.cpp
new file mode 100644 (file)
index 0000000..9353e63
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s -pedantic
+
+namespace PR31692 {
+  struct A {
+    struct X { int n = 0; } x;
+    // Trigger construction of X() from a SFINAE context. This must not mark
+    // any part of X as invalid.
+    static_assert(!__is_constructible(X), "");
+    // Check that X::n is not marked invalid.
+    double &r = x.n; // expected-error {{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}}
+  };
+  // A::X can now be default-constructed.
+  static_assert(__is_constructible(A::X), "");
+}