[cfe-commits] r152615 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/vla.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Mon Mar 12 22:56:41 PDT 2012
Author: rsmith
Date: Tue Mar 13 00:56:40 2012
New Revision: 152615
URL: http://llvm.org/viewvc/llvm-project?rev=152615&view=rev
Log:
PR11925: A function can't have a variably-modified return type. Not even in C++.
Added:
cfe/trunk/test/SemaCXX/vla.cpp
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=152615&r1=152614&r2=152615&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Mar 13 00:56:40 2012
@@ -5266,21 +5266,22 @@
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) &&
Added: cfe/trunk/test/SemaCXX/vla.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vla.cpp?rev=152615&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/vla.cpp (added)
+++ cfe/trunk/test/SemaCXX/vla.cpp Tue Mar 13 00:56:40 2012
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify %s
+
+// PR11925
+int n;
+int (&f())[n]; // expected-error {{function declaration cannot have variably modified type}}
More information about the cfe-commits
mailing list