summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2014-01-04 01:57:42 +0000
committerRichard Trieu <rtrieu@google.com>2014-01-04 01:57:42 +0000
commit658eb68e82e665132e15a96a85384974de20ceef (patch)
tree185a165c8897086352be0f99b3166c423d8ddeac
parent83f1149b30d9131c8f8b26efafd223e119eb4891 (diff)
downloadbcm5719-llvm-658eb68e82e665132e15a96a85384974de20ceef.tar.gz
bcm5719-llvm-658eb68e82e665132e15a96a85384974de20ceef.zip
Ignore qualified templated functions for -Winfinite-recursion. This treats
functions like Foo<5>::run() the same way as run<5>() for this warning. llvm-svn: 198470
-rw-r--r--clang/lib/Sema/AnalysisBasedWarnings.cpp12
-rw-r--r--clang/test/SemaCXX/warn-infinite-recursion.cpp23
2 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 57c0ac311cd..72f8ee1d29d 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -116,6 +116,18 @@ static void checkForFunctionCall(Sema &S, const FunctionDecl *FD,
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()) {
diff --git a/clang/test/SemaCXX/warn-infinite-recursion.cpp b/clang/test/SemaCXX/warn-infinite-recursion.cpp
index 088d4ba3de7..e1b7c5412e1 100644
--- a/clang/test/SemaCXX/warn-infinite-recursion.cpp
+++ b/clang/test/SemaCXX/warn-infinite-recursion.cpp
@@ -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}}
OpenPOWER on IntegriCloud