From: Richard Smith Date: Sat, 11 Feb 2012 18:03:45 +0000 (+0000) Subject: Make sure to try instantiating a templated type which is used in an _Atomic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8327118ff60cd9c4812fba1e5ba4eb3cb5ed3401;p=clang Make sure to try instantiating a templated type which is used in an _Atomic before complaining that it's incomplete. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150308 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index b402d3f2da..7d9a33af11 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -4402,12 +4402,14 @@ QualType Sema::BuildUnaryTransformType(QualType BaseType, QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) { if (!T->isDependentType()) { + // FIXME: It isn't entirely clear whether incomplete atomic types + // are allowed or not; for simplicity, ban them for the moment. + if (RequireCompleteType(Loc, T, + PDiag(diag::err_atomic_specifier_bad_type) << 0)) + return QualType(); + int DisallowedKind = -1; - if (T->isIncompleteType()) - // FIXME: It isn't entirely clear whether incomplete atomic types - // are allowed or not; for simplicity, ban them for the moment. - DisallowedKind = 0; - else if (T->isArrayType()) + if (T->isArrayType()) DisallowedKind = 1; else if (T->isFunctionType()) DisallowedKind = 2; diff --git a/test/Sema/atomic-type.c b/test/Sema/atomic-type.c index 8e725403ae..a4ac552109 100644 --- a/test/Sema/atomic-type.c +++ b/test/Sema/atomic-type.c @@ -16,7 +16,7 @@ extern _Atomic(int (*)(int(*)[10], int(*)[])) mergetest; extern _Atomic(int (*)(int(*)[10], int(*)[10])) mergetest; _Atomic(int()) error1; // expected-error {{_Atomic cannot be applied to function type}} -_Atomic(struct ErrorS) error2; // expected-error {{_Atomic cannot be applied to incomplete type}} +_Atomic(struct ErrorS) error2; // expected-error {{_Atomic cannot be applied to incomplete type}} expected-note {{forward declaration}} _Atomic(int[10]) error3; // expected-error {{_Atomic cannot be applied to array type}} _Atomic(const int) error4; // expected-error {{_Atomic cannot be applied to qualified type}} _Atomic(_Atomic(int)) error5; // expected-error {{_Atomic cannot be applied to atomic type}} diff --git a/test/SemaCXX/atomic-type.cxx b/test/SemaCXX/atomic-type.cxx new file mode 100644 index 0000000000..adaff2a0a2 --- /dev/null +++ b/test/SemaCXX/atomic-type.cxx @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -verify %s + +template struct atomic { + _Atomic(T) value; +}; + +template struct user { + struct inner { char n[sizeof(T)]; }; + atomic i; +}; + +user u;