]> granicus.if.org Git - clang/commitdiff
PR11925: A function can't have a variably-modified return type. Not even in C++.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 13 Mar 2012 05:56:40 +0000 (05:56 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 13 Mar 2012 05:56:40 +0000 (05:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152615 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/vla.cpp [new file with mode: 0644]

index bee542234b092900c4fc1b1f98e95d100dcf0504..57b0e9d9c586b0ae9182d512e7b0a6de8a980ed1 100644 (file)
@@ -5266,21 +5266,22 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
   ProcessDeclAttributes(S, NewFD, D,
                         /*NonInheritable=*/true, /*Inheritable=*/false);
 
+  // Functions returning a variably modified type violate C99 6.7.5.2p2
+  // because all functions have linkage.
+  if (!NewFD->isInvalidDecl() &&
+      NewFD->getResultType()->isVariablyModifiedType()) {
+    Diag(NewFD->getLocation(), diag::err_vm_func_decl);
+    NewFD->setInvalidDecl();
+  }
+
   if (!getLangOpts().CPlusPlus) {
     // Perform semantic checking on the function declaration.
     bool isExplicitSpecialization=false;
     if (!NewFD->isInvalidDecl()) {
-      if (NewFD->getResultType()->isVariablyModifiedType()) {
-        // Functions returning a variably modified type violate C99 6.7.5.2p2
-        // because all functions have linkage.
-        Diag(NewFD->getLocation(), diag::err_vm_func_decl);
-        NewFD->setInvalidDecl();
-      } else {
-        if (NewFD->isMain()) 
-          CheckMain(NewFD, D.getDeclSpec());
-        D.setRedeclaration(CheckFunctionDeclaration(S, NewFD, Previous,
-                                                    isExplicitSpecialization));
-      }
+      if (NewFD->isMain())
+        CheckMain(NewFD, D.getDeclSpec());
+      D.setRedeclaration(CheckFunctionDeclaration(S, NewFD, Previous,
+                                                  isExplicitSpecialization));
     }
     assert((NewFD->isInvalidDecl() || !D.isRedeclaration() ||
             Previous.getResultKind() != LookupResult::FoundOverloaded) &&
diff --git a/test/SemaCXX/vla.cpp b/test/SemaCXX/vla.cpp
new file mode 100644 (file)
index 0000000..d63b633
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify %s
+
+// PR11925
+int n;
+int (&f())[n]; // expected-error {{function declaration cannot have variably modified type}}