r292847 - PR31692: Don't mark a declaration as invalid if we haven't necessarily emitted a (user-visible) error.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 23 15:14:23 PST 2017
Author: rsmith
Date: Mon Jan 23 17:14:23 2017
New Revision: 292847
URL: http://llvm.org/viewvc/llvm-project?rev=292847&view=rev
Log:
PR31692: Don't mark a declaration as invalid if we haven't necessarily emitted a (user-visible) error.
Added:
cfe/trunk/test/SemaCXX/cxx11-default-member-initializers.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=292847&r1=292846&r2=292847&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jan 23 17:14:23 2017
@@ -12383,9 +12383,9 @@ ExprResult Sema::BuildCXXDefaultInitExpr
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();
}
Added: cfe/trunk/test/SemaCXX/cxx11-default-member-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-default-member-initializers.cpp?rev=292847&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx11-default-member-initializers.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx11-default-member-initializers.cpp Mon Jan 23 17:14:23 2017
@@ -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), "");
+}
More information about the cfe-commits
mailing list