From 4c7b490d1921dd93685be9da9033101f99997025 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 11 Feb 2012 18:03:45 +0000 Subject: [PATCH] Make sure to try instantiating a templated type which is used in an _Atomic before complaining that it's incomplete. llvm-svn: 150308 --- clang/lib/Sema/SemaType.cpp | 12 +++++++----- clang/test/Sema/atomic-type.c | 2 +- clang/test/SemaCXX/atomic-type.cxx | 12 ++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 clang/test/SemaCXX/atomic-type.cxx diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index b402d3f2daaa..7d9a33af11f7 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/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/clang/test/Sema/atomic-type.c b/clang/test/Sema/atomic-type.c index 8e725403ae90..a4ac5521091e 100644 --- a/clang/test/Sema/atomic-type.c +++ b/clang/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/clang/test/SemaCXX/atomic-type.cxx b/clang/test/SemaCXX/atomic-type.cxx new file mode 100644 index 000000000000..adaff2a0a2f3 --- /dev/null +++ b/clang/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;