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:
parent
c2ccfd5f8b
commit
6d6bb31926
|
@ -52,6 +52,9 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type
|
||||||
case LIMIT:
|
case LIMIT:
|
||||||
id = "cppcheckLimit";
|
id = "cppcheckLimit";
|
||||||
break;
|
break;
|
||||||
|
case INSTANTIATION:
|
||||||
|
id = "instantiationError";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace tinyxml2 {
|
||||||
|
|
||||||
/** @brief Simple container to be thrown when internal error is detected. */
|
/** @brief Simple container to be thrown when internal error is detected. */
|
||||||
struct InternalError {
|
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);
|
InternalError(const Token *tok, const std::string &errorMsg, Type type = INTERNAL);
|
||||||
const Token *token;
|
const Token *token;
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
|
|
|
@ -2180,7 +2180,7 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok)
|
||||||
|
|
||||||
// Don't simplify "%num% / 0"
|
// Don't simplify "%num% / 0"
|
||||||
if (Token::Match(op, "[/%] 0"))
|
if (Token::Match(op, "[/%] 0"))
|
||||||
break;
|
throw InternalError(op, "Instantiation error: Divide by zero in template instantiation.", InternalError::INSTANTIATION);
|
||||||
|
|
||||||
// Integer operations
|
// Integer operations
|
||||||
if (Token::Match(op, ">>|<<|&|^|%or%")) {
|
if (Token::Match(op, ">>|<<|&|^|%or%")) {
|
||||||
|
|
|
@ -162,6 +162,7 @@ private:
|
||||||
TEST_CASE(template122); // #9147
|
TEST_CASE(template122); // #9147
|
||||||
TEST_CASE(template123); // #9183
|
TEST_CASE(template123); // #9183
|
||||||
TEST_CASE(template124); // #9197
|
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_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_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)
|
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
|
||||||
|
@ -2923,6 +2924,17 @@ private:
|
||||||
ASSERT_EQUALS(exp, tok(code));
|
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>> {..};
|
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
|
||||||
const char code[] = "template <typename T> struct C {};\n"
|
const char code[] = "template <typename T> struct C {};\n"
|
||||||
"template <typename T> struct S {a};\n"
|
"template <typename T> struct S {a};\n"
|
||||||
|
|
Loading…
Reference in New Issue