]> granicus.if.org Git - clang/commitdiff
Make sure to try instantiating a templated type which is used in an _Atomic
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 11 Feb 2012 18:03:45 +0000 (18:03 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 11 Feb 2012 18:03:45 +0000 (18:03 +0000)
before complaining that it's incomplete.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150308 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/Sema/atomic-type.c
test/SemaCXX/atomic-type.cxx [new file with mode: 0644]

index b402d3f2daaa7c489ce5ab3bcabff11a726d2e2a..7d9a33af11f75bc0d9ba27a53b9cc6d6fc83f183 100644 (file)
@@ -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;
index 8e725403ae90b2f3d6d0e1c04c96612e510606b1..a4ac5521091e42eecc7322666e6b101046e9429e 100644 (file)
@@ -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 (file)
index 0000000..adaff2a
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -verify %s
+
+template<typename T> struct atomic {
+  _Atomic(T) value;
+};
+
+template<typename T> struct user {
+  struct inner { char n[sizeof(T)]; };
+  atomic<inner> i;
+};
+
+user<int> u;