<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 3, 2010, at 3:02 AM, Chandler Carruth wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Author: chandlerc<br>Date: Wed Feb 3 05:02:14 2010<br>New Revision: 95220<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=95220&view=rev">http://llvm.org/viewvc/llvm-project?rev=95220&view=rev</a><br>Log:<br>Teach the allocation function overload handling to deal with templates, and<br>prevent a crash on templates when looking for an existing declaration of the<br>predefined global operators. This fixes PR5918.<br><br>Added an easy test case for the overload handling, but testing the crash is<br>a bit trickier. Created a new test that can use multiple runs with a define to<br>trigger which test case is used so we can test this type of issue.<br><br>Added:<br> cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp<br>Modified:<br> cfe/trunk/lib/Sema/SemaExprCXX.cpp<br> cfe/trunk/test/SemaCXX/new-delete.cpp<br><br>Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=95220&r1=95219&r2=95220&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=95220&r1=95219&r2=95220&view=diff</a><br><br>==============================================================================<br>--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)<br>+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Feb 3 05:02:14 2010<br>@@ -630,14 +630,19 @@<br> Alloc != AllocEnd; ++Alloc) {<br> // Even member operator new/delete are implicitly treated as<br> // static, so don't use AddMemberCandidate.<br>- if (FunctionDecl *Fn = <br>- dyn_cast<FunctionDecl>((*Alloc)->getUnderlyingDecl())) {<br>- AddOverloadCandidate(Fn, Alloc.getAccess(), Args, NumArgs, Candidates,<br>- /*SuppressUserConversions=*/false);<br>+<br>+ if (FunctionTemplateDecl *FnTemplate = <br>+ dyn_cast<FunctionTemplateDecl>((*Alloc)->getUnderlyingDecl())) {<br>+ AddTemplateOverloadCandidate(FnTemplate, Alloc.getAccess(),<br>+ /*ExplicitTemplateArgs=*/0, Args, NumArgs,<br>+ Candidates,<br>+ /*SuppressUserConversions=*/false);<br> continue;<br>- } <br>- <br>- // FIXME: Handle function templates<br>+ }<br>+<br>+ FunctionDecl *Fn = cast<FunctionDecl>((*Alloc)->getUnderlyingDecl());<br>+ AddOverloadCandidate(Fn, Alloc.getAccess(), Args, NumArgs, Candidates,<br>+ /*SuppressUserConversions=*/false);<br> }<br><br> // Do the resolution.<br>@@ -768,12 +773,16 @@<br> DeclContext::lookup_iterator Alloc, AllocEnd;<br> for (llvm::tie(Alloc, AllocEnd) = GlobalCtx->lookup(Name);<br> Alloc != AllocEnd; ++Alloc) {<br>- // FIXME: Do we need to check for default arguments here?<br>- FunctionDecl *Func = cast<FunctionDecl>(*Alloc);<br>- if (Func->getNumParams() == 1 &&<br>+ // Only look at non-template functions, as it is the predefined,<br>+ // non-templated allocation function we are trying to declare here.<br>+ if (FunctionDecl *Func = dyn_cast<FunctionDecl>(*Alloc)) {<br>+ QualType InitialParamType =<br> Context.getCanonicalType(<br>- Func->getParamDecl(0)->getType().getUnqualifiedType()) == Argument)<br>- return;<br>+ Func->getParamDecl(0)->getType().getUnqualifiedType());<br>+ // FIXME: Do we need to check for default arguments here?<br>+ if (Func->getNumParams() == 1 && InitialParamType == Argument)<br>+ return;<br>+ }<br> }<br> }<br><br><br>Added: cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp?rev=95220&view=auto">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp?rev=95220&view=auto</a><br><br>==============================================================================<br>--- cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp (added)<br>+++ cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp Wed Feb 3 05:02:14 2010<br>@@ -0,0 +1,18 @@<br>+// RUN: %clang_cc1 -DTEMPLATE_OVERLOAD -fsyntax-only -verify %s<br>+<br>+#include <stddef.h><br>+<br>+// Note that each test must be run separately so it can be the first operator<br>+// new declaration in the file.<br></div></blockquote><div><br></div>Did you also want a second run line without TEMPLATE_OVERLOAD, e.g.,</div><div><br></div><div> <span class="Apple-style-span" style="color: rgb(178, 34, 34); font-family: monospace; font-style: italic; white-space: pre; ">RUN: %clang_cc1 -fsyntax-only -verify %s</span><div><br></div></div> - Doug</body></html>