fix crash in daca gcc-avr from intentional bad instantiation test (#1994)

* fix crash in daca gcc-avr from intentional bad instantiation test

* fix cppcheck warning
This commit is contained in:
IOBYTE 2019-07-15 06:41:06 -04:00 committed by Daniel Marjamäki
parent c2ccfd5f8b
commit 6d6bb31926
4 changed files with 17 additions and 2 deletions

View File

@ -52,6 +52,9 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type
case LIMIT:
id = "cppcheckLimit";
break;
case INSTANTIATION:
id = "instantiationError";
break;
}
}

View File

@ -54,7 +54,7 @@ namespace tinyxml2 {
/** @brief Simple container to be thrown when internal error is detected. */
struct InternalError {
enum Type {AST, SYNTAX, UNKNOWN_MACRO, INTERNAL, LIMIT};
enum Type {AST, SYNTAX, UNKNOWN_MACRO, INTERNAL, LIMIT, INSTANTIATION};
InternalError(const Token *tok, const std::string &errorMsg, Type type = INTERNAL);
const Token *token;
std::string errorMessage;

View File

@ -2180,7 +2180,7 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok)
// Don't simplify "%num% / 0"
if (Token::Match(op, "[/%] 0"))
break;
throw InternalError(op, "Instantiation error: Divide by zero in template instantiation.", InternalError::INSTANTIATION);
// Integer operations
if (Token::Match(op, ">>|<<|&|^|%or%")) {

View File

@ -162,6 +162,7 @@ private:
TEST_CASE(template122); // #9147
TEST_CASE(template123); // #9183
TEST_CASE(template124); // #9197
TEST_CASE(template125);
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
@ -2923,6 +2924,17 @@ private:
ASSERT_EQUALS(exp, tok(code));
}
void template125() {
ASSERT_THROW(tok("template<int M, int N>\n"
"class GCD {\n"
"public:\n"
" enum { val = (N == 0) ? M : GCD<N, M % N>::val };\n"
"};\n"
"int main() {\n"
" GCD< 1, 0 >::val;\n"
"}"), InternalError);
}
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"