PR11925: A function can't have a variably-modified return type. Not even in C++.

llvm-svn: 152615
This commit is contained in:
Richard Smith 2012-03-13 05:56:40 +00:00
parent ac499ab244
commit 84208dcf02
2 changed files with 17 additions and 11 deletions

View File

@ -5266,22 +5266,23 @@ 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));
}
}
assert((NewFD->isInvalidDecl() || !D.isRedeclaration() ||
Previous.getResultKind() != LookupResult::FoundOverloaded) &&
"previous declaration set still overloaded");

View File

@ -0,0 +1,5 @@
// RUN: %clang_cc1 -verify %s
// PR11925
int n;
int (&f())[n]; // expected-error {{function declaration cannot have variably modified type}}