Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 0ed7413

Browse files
committed
PR31692: Don't mark a declaration as invalid if we haven't necessarily emitted a (user-visible) error.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292847 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 42be00e commit 0ed7413

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Diff for: lib/Sema/SemaDeclCXX.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12383,9 +12383,9 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
1238312383
Diag(Loc, diag::err_in_class_initializer_not_yet_parsed)
1238412384
<< OutermostClass << Field;
1238512385
Diag(Field->getLocEnd(), diag::note_in_class_initializer_not_yet_parsed);
12386-
12387-
// Don't diagnose this again.
12388-
Field->setInvalidDecl();
12386+
// Recover by marking the field invalid, unless we're in a SFINAE context.
12387+
if (!isSFINAEContext())
12388+
Field->setInvalidDecl();
1238912389
return ExprError();
1239012390
}
1239112391

Diff for: test/SemaCXX/cxx11-default-member-initializers.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -std=c++11 -verify %s -pedantic
2+
3+
namespace PR31692 {
4+
struct A {
5+
struct X { int n = 0; } x;
6+
// Trigger construction of X() from a SFINAE context. This must not mark
7+
// any part of X as invalid.
8+
static_assert(!__is_constructible(X), "");
9+
// Check that X::n is not marked invalid.
10+
double &r = x.n; // expected-error {{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}}
11+
};
12+
// A::X can now be default-constructed.
13+
static_assert(__is_constructible(A::X), "");
14+
}

0 commit comments

Comments
 (0)