forked from OSchip/llvm-project
PR11925: A function can't have a variably-modified return type. Not even in C++.
llvm-svn: 152615
This commit is contained in:
parent
ac499ab244
commit
84208dcf02
|
@ -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) &&
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// RUN: %clang_cc1 -verify %s
|
||||
|
||||
// PR11925
|
||||
int n;
|
||||
int (&f())[n]; // expected-error {{function declaration cannot have variably modified type}}
|
Loading…
Reference in New Issue