From: Richard Smith Date: Tue, 13 Mar 2012 05:56:40 +0000 (+0000) Subject: PR11925: A function can't have a variably-modified return type. Not even in C++. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b03a9df68140a393cbef73a23115a0818aff6010;p=clang PR11925: A function can't have a variably-modified return type. Not even in C++. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152615 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index bee542234b..57b0e9d9c5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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 index 0000000000..d63b6335f4 --- /dev/null +++ b/test/SemaCXX/vla.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -verify %s + +// PR11925 +int n; +int (&f())[n]; // expected-error {{function declaration cannot have variably modified type}}