From af1b0cfddf832ed5188234f24446c468952dbd4a Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Fri, 17 Jul 2015 21:30:34 +0200 Subject: [PATCH] Ticket #6835: Don't get confused by parentheses while detecting template parameter default values. --- lib/templatesimplifier.cpp | 5 +++++ test/testgarbage.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5bc08e5ef..15558d341 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -572,6 +572,11 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list &temp continue; } + if (tok->str() == "(") { // Ticket #6835 + tok = tok->link(); + continue; + } + if (tok->str() == "<" && templateParameters(tok)) ++templateParmDepth; diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 247ac8d91..4d5af8b88 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -140,6 +140,7 @@ private: TEST_CASE(garbageCode98); TEST_CASE(garbageCode99); TEST_CASE(garbageCode100); + TEST_CASE(garbageCode101); // #6835 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -791,6 +792,13 @@ private: checkCode("( ) { ( i< ) } int foo ( ) { int i ; ( for ( i => 1 ) ; ) }"); } + void garbageCode101() { // #6835 + // Reported case + checkCode("template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 }"); + // Reduced case + checkCode("template < class =( , ) X = 1> struct A {}; A a;"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"