зеркало из https://github.com/microsoft/clang-1.git
Static variables and functions won't collide with standard library
functions, so if we're declaring a static we should implicitly declare a library function by the same name (e.g., malloc, strdup). Fixes PR3592. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64736 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
85b2a47ec0
Коммит
9add31798f
|
@ -271,6 +271,10 @@ unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const {
|
|||
// function. Determine whether it actually refers to the C library
|
||||
// function or whether it just has the same name.
|
||||
|
||||
// If this is a static function, it's not a builtin.
|
||||
if (getStorageClass() == Static)
|
||||
return 0;
|
||||
|
||||
// If this function is at translation-unit scope and we're not in
|
||||
// C++, it refers to the C library function.
|
||||
if (!Context.getLangOptions().CPlusPlus &&
|
||||
|
|
|
@ -1304,7 +1304,9 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl,
|
|||
// See if this is a redefinition of a variable in the same scope.
|
||||
if (!D.getCXXScopeSpec().isSet() && !D.getCXXScopeSpec().isInvalid()) {
|
||||
DC = CurContext;
|
||||
PrevDecl = LookupName(S, Name, LookupOrdinaryName, true, true,
|
||||
PrevDecl = LookupName(S, Name, LookupOrdinaryName, true,
|
||||
D.getDeclSpec().getStorageClassSpec() !=
|
||||
DeclSpec::SCS_static,
|
||||
D.getIdentifierLoc());
|
||||
} else { // Something like "int foo::x;"
|
||||
DC = static_cast<DeclContext*>(D.getCXXScopeSpec().getScopeRep());
|
||||
|
|
|
@ -41,4 +41,3 @@ void * realloc(void *p, int size) { // expected-warning{{incompatible redeclarat
|
|||
// expected-note{{use -ffreestanding to compile as a freestanding implementation}}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// RUN: clang -fsyntax-only -verify %s
|
||||
|
||||
// PR3592
|
||||
static void* malloc(int);
|
||||
static void* malloc(int size) {
|
||||
return ((void*)0); /*do not use heap in this file*/
|
||||
}
|
Загрузка…
Ссылка в новой задаче