Skip to content

Commit 267d23f

Browse files
authored
gnu.cfg: Define __typeof__ as typeof, fix simplifyTypedef() (cppcheck-opensource#2260)
`__typeof__` is just an alternative keyword for `typeof`, see https://gcc.gnu.org/onlinedocs/gcc/Typeof.html Since `typeof` is handled in several checkers it makes sense to define `__typeof__` as `typeof`. Tokenizer::simplifyTypedef(): Use `typeof` instead of `__typeof__` to be consistent with the rest of the code.
1 parent bf5c90a commit 267d23f

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

cfg/gnu.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<define name="__builtin_nanl(str)" value="nanl(str)"/>
4848
<define name="__builtin_signbit(value)" value="signbit(value)"/>
4949
<define name="__extension__" value=""/>
50+
<define name="__typeof__(T)" value="typeof(T)"/>
5051
<!-- void *__builtin_alloca (size_t size) -->
5152
<!-- alloca() is often defined as __builtin_alloca() so the define above does not work always -->
5253
<!-- void *alloca(size_t size); -->

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,8 @@ void Tokenizer::simplifyTypedef()
842842
}
843843
}
844844

845-
// typeof: typedef __typeof__ ( ... ) type;
846-
else if (Token::simpleMatch(tokOffset->previous(), "__typeof__ (") &&
845+
// typeof: typedef typeof ( ... ) type;
846+
else if (Token::simpleMatch(tokOffset->previous(), "typeof (") &&
847847
Token::Match(tokOffset->link(), ") %type% ;")) {
848848
argStart = tokOffset;
849849
argEnd = tokOffset->link();

test/testsimplifytypedef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,10 +1626,10 @@ class TestSimplifyTypedef : public TestFixture {
16261626
}
16271627

16281628
void simplifyTypedef64() {
1629-
const char code[] = "typedef __typeof__(__type1() + __type2()) __type;"
1629+
const char code[] = "typedef typeof(__type1() + __type2()) __type;"
16301630
"__type t;";
16311631
const std::string actual(tok(code));
1632-
ASSERT_EQUALS("__typeof__ ( __type1 ( ) + __type2 ( ) ) t ;", actual);
1632+
ASSERT_EQUALS("typeof ( __type1 ( ) + __type2 ( ) ) t ;", actual);
16331633
ASSERT_EQUALS("", errout.str());
16341634
}
16351635

0 commit comments

Comments
 (0)