summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/ASTContext.cpp3
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp3
-rw-r--r--clang/test/SemaCXX/type-traits.cpp8
3 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e6471be2041..34a925020e8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2279,6 +2279,9 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const {
if (Ty->isRecordType()) {
const RecordDecl *Record = Ty->getAs<RecordType>()->getDecl();
+ if (Record->isInvalidDecl())
+ return false;
+
if (Record->isUnion())
return unionHasUniqueObjectRepresentations(*this, Record);
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 9c842ded1e1..641d583944f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4958,7 +4958,7 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT,
EnterExpressionEvaluationContext Unevaluated(
Self, Sema::ExpressionEvaluationContext::Unevaluated);
Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true);
- Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl());
+ Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); {
ExprResult Result = Self.BuildBinOp(/*S=*/nullptr, KeyLoc, BO_Assign, &Lhs,
&Rhs);
if (Result.isInvalid() || SFINAE.hasErrorOccurred())
@@ -4981,6 +4981,7 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT,
llvm_unreachable("unhandled type trait");
return false;
+ }
}
default: llvm_unreachable("not a BTT");
}
diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index d4d19682182..b334e507554 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2661,3 +2661,11 @@ static_assert(sizeof(CanBeUniqueIfNoPadding) != 16 ||
has_unique_object_representations<CanBeUniqueIfNoPadding>::value,
"inherit from std layout");
+namespace ErrorType {
+ struct S; //expected-note{{forward declaration of 'ErrorType::S'}}
+
+ struct T {
+ S t; //expected-error{{field has incomplete type 'ErrorType::S'}}
+ };
+ bool b = __has_unique_object_representations(T);
+};
OpenPOWER on IntegriCloud