r198470 - Ignore qualified templated functions for -Winfinite-recursion. This treats
Richard Trieu
rtrieu at google.com
Fri Jan 3 17:57:42 PST 2014
Author: rtrieu
Date: Fri Jan 3 19:57:42 2014
New Revision: 198470
URL: http://llvm.org/viewvc/llvm-project?rev=198470&view=rev
Log:
Ignore qualified templated functions for -Winfinite-recursion. This treats
functions like Foo<5>::run() the same way as run<5>() for this warning.
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=198470&r1=198469&r2=198470&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Jan 3 19:57:42 2014
@@ -116,6 +116,18 @@ static void checkForFunctionCall(Sema &S
const CallExpr *CE = dyn_cast<CallExpr>(I->getAs<CFGStmt>()->getStmt());
if (CE && CE->getCalleeDecl() &&
CE->getCalleeDecl()->getCanonicalDecl() == FD) {
+
+ // Skip function calls which are qualified with a templated class.
+ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(
+ CE->getCallee()->IgnoreParenImpCasts())) {
+ if (NestedNameSpecifier *NNS = DRE->getQualifier()) {
+ if (NNS->getKind() == NestedNameSpecifier::TypeSpec &&
+ isa<TemplateSpecializationType>(NNS->getAsType())) {
+ continue;
+ }
+ }
+ }
+
if (const CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(CE)) {
if (isa<CXXThisExpr>(MCE->getImplicitObjectArgument()) ||
!MCE->getMethodDecl()->isVirtual()) {
Modified: cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp?rev=198470&r1=198469&r2=198470&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp Fri Jan 3 19:57:42 2014
@@ -127,3 +127,26 @@ int DoStuff() {
return 0;
}
int stuff = DoStuff<0, 1>();
+
+template<int x>
+struct Wrapper {
+ static int run() {
+ // Similar to the above, Wrapper<0>::run() will discard the if statement.
+ if (x == 1)
+ return 0;
+ return Wrapper<x/2>::run();
+ }
+ static int run2() { // expected-warning{{call itself}}
+ return run2();
+ }
+};
+
+template <int x>
+int test_wrapper() {
+ if (x != 0)
+ return Wrapper<x>::run() +
+ Wrapper<x>::run2(); // expected-note{{instantiation}}
+ return 0;
+}
+
+int wrapper_sum = test_wrapper<2>(); // expected-note{{instantiation}}
More information about the cfe-commits
mailing list