From debcd500a0e184cc17254622411a9cc8e9dcfaa0 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 16 May 2014 02:14:42 +0000 Subject: [PATCH] Push implicitly-declared allocation functions into the IdResolver. Otherwise, declaration merging in modules is unable to find them and we get bogus errors and even crashes. llvm-svn: 208944 --- clang/lib/Sema/SemaExprCXX.cpp | 4 +--- clang/test/Modules/Inputs/cxx-decls-imported.h | 2 ++ clang/test/Modules/cxx-decls.cpp | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index b344225ab836..bfb209a074f8 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2109,10 +2109,8 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, } Alloc->setParams(ArrayRef(ParamDecls, NumParams)); - // FIXME: Also add this declaration to the IdentifierResolver, but - // make sure it is at the end of the chain to coincide with the - // global scope. Context.getTranslationUnitDecl()->addDecl(Alloc); + IdResolver.tryAddTopLevelDecl(Alloc, Name); } FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc, diff --git a/clang/test/Modules/Inputs/cxx-decls-imported.h b/clang/test/Modules/Inputs/cxx-decls-imported.h index 959d3feaaf02..5c7f6fc34427 100644 --- a/clang/test/Modules/Inputs/cxx-decls-imported.h +++ b/clang/test/Modules/Inputs/cxx-decls-imported.h @@ -18,3 +18,5 @@ private: static_assert(!__is_trivial(HasNontrivialDefaultConstructor), ""); static_assert(!__has_trivial_constructor(HasNontrivialDefaultConstructor), ""); + +void *operator new[](__SIZE_TYPE__); diff --git a/clang/test/Modules/cxx-decls.cpp b/clang/test/Modules/cxx-decls.cpp index d37594afb567..49ba8340d3e4 100644 --- a/clang/test/Modules/cxx-decls.cpp +++ b/clang/test/Modules/cxx-decls.cpp @@ -3,6 +3,8 @@ // expected-no-diagnostics +void use_implicit_new() { operator new[](3); } + @import dummy; @import cxx_decls.imported; @@ -22,3 +24,5 @@ void test_friends(HasFriends s) { static_assert(!__is_trivial(HasNontrivialDefaultConstructor), ""); static_assert(!__has_trivial_constructor(HasNontrivialDefaultConstructor), ""); + +void use_implicit_new_again() { operator new[](3); }