Fixed #6930 (Token: need function that says if the token comes from instantiated template argument)
This commit is contained in:
parent
323e9ab509
commit
bbeff99cc3
|
@ -152,7 +152,7 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
|||
}
|
||||
return false;
|
||||
}
|
||||
if (macro && (tok1->isExpandedMacro() || tok2->isExpandedMacro()))
|
||||
if (macro && (tok1->isExpandedMacro() || tok2->isExpandedMacro() || tok1->isTemplateArg() || tok2->isTemplateArg()))
|
||||
return false;
|
||||
if (tok1->isComplex() != tok2->isComplex())
|
||||
return false;
|
||||
|
|
|
@ -1034,6 +1034,7 @@ void TemplateSimplifier::expandTemplate(
|
|||
else if (typeindentlevel > 0 && typetok->str() == ">")
|
||||
--typeindentlevel;
|
||||
tokenlist.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
|
||||
tokenlist.back()->isTemplateArg(true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -422,6 +422,12 @@ public:
|
|||
void isEnumType(bool value) {
|
||||
setFlag(fIsEnumType, value);
|
||||
}
|
||||
bool isTemplateArg() const {
|
||||
return getFlag(fIsTemplateArg);
|
||||
}
|
||||
void isTemplateArg(bool value) {
|
||||
setFlag(fIsTemplateArg, value);
|
||||
}
|
||||
|
||||
static const Token *findsimplematch(const Token * const startTok, const char pattern[]);
|
||||
static const Token *findsimplematch(const Token * const startTok, const char pattern[], const Token * const end);
|
||||
|
@ -898,6 +904,7 @@ private:
|
|||
fIsEnumType = (1 << 19), // enumeration type
|
||||
fIsName = (1 << 20),
|
||||
fIsLiteral = (1 << 21),
|
||||
fIsTemplateArg = (1 << 22),
|
||||
};
|
||||
|
||||
unsigned int _flags;
|
||||
|
|
|
@ -129,6 +129,7 @@ private:
|
|||
TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)
|
||||
TEST_CASE(duplicateExpression6); // ticket #4639
|
||||
TEST_CASE(duplicateExpressionTernary); // #6391
|
||||
TEST_CASE(duplicateExpressionTemplate); // #6930
|
||||
|
||||
TEST_CASE(checkSignOfUnsignedVariable);
|
||||
TEST_CASE(checkSignOfPointer);
|
||||
|
@ -3875,6 +3876,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void duplicateExpressionTemplate() { // #6930
|
||||
check("template <int I> void f() {\n"
|
||||
" if (I >= 0 && I < 3) {}\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"static auto a = f<0>();");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkSignOfUnsignedVariable() {
|
||||
check(
|
||||
"void foo() {\n"
|
||||
|
|
Loading…
Reference in New Issue