2015-06-22 20:43:26 +02:00
2014-09-24 13:45:56 +02:00
/*
* Cppcheck - A tool for static C / C + + code analysis
2015-01-03 12:14:58 +01:00
* Copyright ( C ) 2007 - 2015 Daniel Marjamäki and Cppcheck team .
2014-09-24 13:45:56 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "testsuite.h"
# include "tokenize.h"
# include "token.h"
# include "settings.h"
2014-09-30 09:22:33 +02:00
# include "check.h"
2014-09-24 13:45:56 +02:00
class TestGarbage : public TestFixture {
public :
2014-11-20 14:20:09 +01:00
TestGarbage ( ) : TestFixture ( " TestGarbage " ) {
2014-09-24 13:45:56 +02:00
}
private :
2014-11-20 14:20:09 +01:00
void run ( ) {
2014-09-24 13:45:56 +02:00
// don't freak out when the syntax is wrong
TEST_CASE ( wrong_syntax1 ) ;
TEST_CASE ( wrong_syntax2 ) ;
TEST_CASE ( wrong_syntax3 ) ; // #3544
TEST_CASE ( wrong_syntax4 ) ; // #3618
TEST_CASE ( wrong_syntax_if_macro ) ; // #2518 - if MACRO()
TEST_CASE ( wrong_syntax_class_x_y ) ; // #3585 - class x y { };
TEST_CASE ( syntax_case_default ) ;
TEST_CASE ( garbageCode1 ) ;
TEST_CASE ( garbageCode2 ) ; // #4300
TEST_CASE ( garbageCode3 ) ; // #4869
TEST_CASE ( garbageCode4 ) ; // #4887
TEST_CASE ( garbageCode5 ) ; // #5168
TEST_CASE ( garbageCode6 ) ; // #5214
TEST_CASE ( garbageCode7 ) ;
TEST_CASE ( garbageCode8 ) ; // #5511
TEST_CASE ( garbageCode9 ) ; // #5604
TEST_CASE ( garbageCode10 ) ; // #6127
2014-09-28 22:05:05 +02:00
TEST_CASE ( garbageCode11 ) ;
2014-09-29 19:44:25 +02:00
TEST_CASE ( garbageCode12 ) ;
2014-10-16 10:59:46 +02:00
TEST_CASE ( garbageCode13 ) ; // Ticket #2607 - crash
2015-01-07 16:24:33 +01:00
TEST_CASE ( garbageCode14 ) ; // Ticket #5595 - crash
2014-10-16 10:59:46 +02:00
TEST_CASE ( garbageCode15 ) ; // Ticket #5203
TEST_CASE ( garbageCode16 ) ;
TEST_CASE ( garbageCode17 ) ;
TEST_CASE ( garbageCode18 ) ;
TEST_CASE ( garbageCode19 ) ;
TEST_CASE ( garbageCode20 ) ;
TEST_CASE ( garbageCode21 ) ;
TEST_CASE ( garbageCode22 ) ;
TEST_CASE ( garbageCode23 ) ;
2015-01-07 16:24:33 +01:00
TEST_CASE ( garbageCode24 ) ; // Ticket #6361 - crash
2015-01-21 10:04:24 +01:00
TEST_CASE ( garbageCode25 ) ;
TEST_CASE ( garbageCode26 ) ;
TEST_CASE ( garbageCode27 ) ;
TEST_CASE ( garbageCode28 ) ;
2015-01-31 20:12:02 +01:00
TEST_CASE ( garbageCode29 ) ;
2015-02-22 13:09:39 +01:00
TEST_CASE ( garbageCode30 ) ; // #5867
2015-02-24 11:15:23 +01:00
TEST_CASE ( garbageCode31 ) ; // #6539
2015-03-30 15:33:24 +02:00
TEST_CASE ( garbageCode32 ) ; // #6135
2015-04-01 12:43:03 +02:00
TEST_CASE ( garbageCode33 ) ; // #6613
2015-04-13 20:18:07 +02:00
TEST_CASE ( garbageCode34 ) ; // #6626
TEST_CASE ( garbageCode35 ) ; // #2599, #2604
2015-05-01 17:13:02 +02:00
TEST_CASE ( garbageCode36 ) ; // #6334
2015-05-07 20:34:57 +02:00
TEST_CASE ( garbageCode37 ) ; // #5166
2015-05-10 10:00:46 +02:00
TEST_CASE ( garbageCode38 ) ; // #6666
2015-05-13 13:02:33 +02:00
TEST_CASE ( garbageCode39 ) ; // #6686
2015-05-22 22:18:42 +02:00
TEST_CASE ( garbageCode40 ) ; // #6620
TEST_CASE ( garbageCode41 ) ; // #6685
2015-05-23 20:29:44 +02:00
TEST_CASE ( garbageCode42 ) ; // #5760
2015-05-23 23:18:59 +02:00
TEST_CASE ( garbageCode43 ) ; // #6703
2015-05-24 08:16:34 +02:00
TEST_CASE ( garbageCode44 ) ; // #6704
2015-05-24 10:03:50 +02:00
TEST_CASE ( garbageCode45 ) ; // #6608
2015-05-27 21:12:33 +02:00
TEST_CASE ( garbageCode46 ) ; // #6705
2015-05-27 21:39:31 +02:00
TEST_CASE ( garbageCode47 ) ; // #6706
2015-05-28 21:12:02 +02:00
TEST_CASE ( garbageCode48 ) ; // #6712
2015-05-28 21:38:20 +02:00
TEST_CASE ( garbageCode49 ) ; // #6715
2015-05-29 19:15:41 +02:00
TEST_CASE ( garbageCode50 ) ; // #6718
TEST_CASE ( garbageCode51 ) ; // #6719
2015-05-29 20:20:05 +02:00
TEST_CASE ( garbageCode52 ) ; // #6720
TEST_CASE ( garbageCode53 ) ; // #6721
2015-05-29 21:44:00 +02:00
TEST_CASE ( garbageCode54 ) ; // #6722
2015-05-30 19:15:53 +02:00
TEST_CASE ( garbageCode55 ) ; // #6724
2015-05-30 20:55:36 +02:00
TEST_CASE ( garbageCode56 ) ; // #6713
2015-06-01 13:46:13 +02:00
TEST_CASE ( garbageCode57 ) ; // #6733
2015-06-02 20:09:12 +02:00
TEST_CASE ( garbageCode58 ) ; // #6732
2015-06-01 22:09:56 +02:00
TEST_CASE ( garbageCode59 ) ; // #6735
TEST_CASE ( garbageCode60 ) ; // #6736
2015-06-02 18:28:43 +02:00
TEST_CASE ( garbageCode61 ) ;
2015-06-02 19:07:26 +02:00
TEST_CASE ( garbageCode62 ) ;
2015-06-02 19:40:20 +02:00
TEST_CASE ( garbageCode63 ) ;
2015-06-02 19:48:20 +02:00
TEST_CASE ( garbageCode64 ) ;
2015-06-02 20:09:12 +02:00
TEST_CASE ( garbageCode65 ) ;
2015-06-02 20:15:21 +02:00
TEST_CASE ( garbageCode66 ) ;
2015-06-02 21:20:41 +02:00
TEST_CASE ( garbageCode67 ) ;
TEST_CASE ( garbageCode68 ) ;
2015-06-02 21:52:08 +02:00
TEST_CASE ( garbageCode69 ) ;
2015-06-02 22:26:17 +02:00
TEST_CASE ( garbageCode70 ) ;
2015-06-03 08:59:38 +02:00
TEST_CASE ( garbageCode71 ) ;
2015-06-03 10:39:19 +02:00
TEST_CASE ( garbageCode72 ) ;
TEST_CASE ( garbageCode73 ) ;
2015-06-03 11:39:30 +02:00
TEST_CASE ( garbageCode74 ) ;
2015-06-03 17:17:53 +02:00
TEST_CASE ( garbageCode75 ) ;
TEST_CASE ( garbageCode76 ) ;
2015-06-05 14:34:53 +02:00
TEST_CASE ( garbageCode77 ) ;
TEST_CASE ( garbageCode78 ) ;
TEST_CASE ( garbageCode79 ) ;
2015-06-06 13:11:32 +02:00
TEST_CASE ( garbageCode80 ) ;
TEST_CASE ( garbageCode81 ) ;
2015-06-07 13:35:51 +02:00
TEST_CASE ( garbageCode82 ) ;
2015-06-14 22:18:28 +02:00
TEST_CASE ( garbageCode83 ) ;
2015-06-22 11:12:46 +02:00
TEST_CASE ( garbageCode84 ) ;
2015-06-22 20:43:26 +02:00
TEST_CASE ( garbageCode85 ) ;
2015-06-23 17:59:01 +02:00
TEST_CASE ( garbageCode86 ) ;
2015-06-24 16:54:23 +02:00
TEST_CASE ( garbageCode87 ) ;
2015-06-24 20:22:28 +02:00
TEST_CASE ( garbageCode88 ) ;
2015-06-24 20:47:04 +02:00
TEST_CASE ( garbageCode89 ) ;
2015-06-25 07:47:40 +02:00
TEST_CASE ( garbageCode90 ) ;
2015-06-25 08:57:09 +02:00
TEST_CASE ( garbageCode91 ) ;
2015-06-25 20:48:05 +02:00
TEST_CASE ( garbageCode92 ) ;
2015-06-29 19:56:02 +02:00
TEST_CASE ( garbageCode93 ) ;
2015-06-30 12:16:55 +02:00
TEST_CASE ( garbageCode94 ) ;
2015-07-01 07:50:13 +02:00
TEST_CASE ( garbageCode95 ) ;
2015-07-01 16:31:49 +02:00
TEST_CASE ( garbageCode96 ) ;
TEST_CASE ( garbageCode97 ) ;
2015-07-14 21:07:10 +02:00
TEST_CASE ( garbageCode98 ) ;
2015-07-15 15:18:22 +02:00
TEST_CASE ( garbageCode99 ) ;
TEST_CASE ( garbageCode100 ) ;
2015-07-17 21:30:34 +02:00
TEST_CASE ( garbageCode101 ) ; // #6835
2015-07-20 19:04:34 +02:00
TEST_CASE ( garbageCode102 ) ; // #6846
2015-07-20 22:33:32 +02:00
TEST_CASE ( garbageCode103 ) ; // #6824
2015-07-21 13:40:50 +02:00
TEST_CASE ( garbageCode104 ) ; // #6847
2015-07-22 13:32:34 +02:00
TEST_CASE ( garbageCode105 ) ; // #6859
2014-10-16 10:59:46 +02:00
TEST_CASE ( garbageValueFlow ) ;
TEST_CASE ( garbageSymbolDatabase ) ;
TEST_CASE ( garbageAST ) ;
2015-01-18 13:13:52 +01:00
TEST_CASE ( templateSimplifierCrashes ) ;
2014-09-24 13:45:56 +02:00
}
2015-07-01 07:50:13 +02:00
std : : string checkCode ( const char code [ ] , const std : : string & filename = " test.cpp " ) {
// double the tests - run each example as C as well as C++
const std : : string alternatefilename = ( filename = = " test.c " ) ? " test.cpp " : " test.c " ;
// run alternate check first. It should only ensure stability
try {
checkCodeInternal ( code , alternatefilename ) ;
} catch ( InternalError & ) {
}
2015-06-30 19:40:22 +02:00
2015-07-01 07:50:13 +02:00
return checkCodeInternal ( code , filename ) ;
}
2015-06-30 19:40:22 +02:00
std : : string checkCodeInternal ( const char code [ ] , const std : : string & filename ) {
2014-09-24 13:45:56 +02:00
errout . str ( " " ) ;
Settings settings ;
settings . debugwarnings = true ;
2014-09-29 19:44:25 +02:00
settings . addEnabled ( " style " ) ;
settings . addEnabled ( " warning " ) ;
settings . addEnabled ( " portability " ) ;
settings . addEnabled ( " performance " ) ;
settings . inconclusive = true ;
settings . experimental = true ;
2014-09-24 13:45:56 +02:00
// tokenize..
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
2015-07-01 07:50:13 +02:00
tokenizer . tokenize ( istr , filename . c_str ( ) ) ;
2014-09-24 13:45:56 +02:00
2014-09-30 08:54:27 +02:00
// call all "runChecks" in all registered Check classes
for ( std : : list < Check * > : : const_iterator it = Check : : instances ( ) . begin ( ) ; it ! = Check : : instances ( ) . end ( ) ; + + it ) {
( * it ) - > runChecks ( & tokenizer , & settings , this ) ;
2014-09-30 10:37:55 +02:00
}
tokenizer . simplifyTokenList2 ( ) ;
// call all "runSimplifiedChecks" in all registered Check classes
for ( std : : list < Check * > : : const_iterator it = Check : : instances ( ) . begin ( ) ; it ! = Check : : instances ( ) . end ( ) ; + + it ) {
2014-09-30 08:54:27 +02:00
( * it ) - > runSimplifiedChecks ( & tokenizer , & settings , this ) ;
}
2014-09-24 13:45:56 +02:00
return tokenizer . tokens ( ) - > stringifyList ( false , false , false , true , false , 0 , 0 ) ;
}
2014-11-20 14:20:09 +01:00
void wrong_syntax1 ( ) {
2014-09-24 13:45:56 +02:00
{
const char code [ ] = " TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;)) " ;
ASSERT_EQUALS ( " TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) ) " , checkCode ( code ) ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
{
const char code [ ] = " struct A { template<int> struct { }; }; " ;
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
}
{
const char code [ ] = " enum ABC { A,B, typedef enum { C } }; " ;
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
}
}
2014-11-20 14:20:09 +01:00
void wrong_syntax2 ( ) { // #3504
2014-09-24 13:45:56 +02:00
const char code [ ] = " void f() { \n "
" X<int> x; \n "
" Y<int, int, int, int, int, char> y; \n "
" } \n "
" \n "
" void G( template <typename T> class (j) ) {} " ;
// don't segfault..
checkCode ( code ) ;
}
2014-11-20 14:20:09 +01:00
void wrong_syntax3 ( ) { // #3544
2014-09-24 13:45:56 +02:00
const char code [ ] = " X #define \n "
" { \n "
" ( \n "
" for( #endif typedef typedef cb[N] ) \n "
" ca[N]; = cb[i] \n "
" ) \n "
" } " ;
Settings settings ;
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
try {
tokenizer . tokenize ( istr , " test.cpp " ) ;
assertThrowFail ( __FILE__ , __LINE__ ) ;
} catch ( InternalError & e ) {
ASSERT_EQUALS ( " Analysis failed. If the code is valid then please report this failure. " , e . errorMessage ) ;
ASSERT_EQUALS ( " cppcheckError " , e . id ) ;
ASSERT_EQUALS ( 5 , e . token - > linenr ( ) ) ;
}
}
2014-11-20 14:20:09 +01:00
void wrong_syntax4 ( ) { // #3618
2014-09-24 13:45:56 +02:00
const char code [ ] = " typedef void (x) (int); return x& " ;
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void wrong_syntax_if_macro ( ) {
2014-09-24 13:45:56 +02:00
// #2518 #4171
ASSERT_THROW ( checkCode ( " void f() { if MACRO(); } " ) , InternalError ) ;
// #4668 - note there is no semicolon after MACRO()
ASSERT_THROW ( checkCode ( " void f() { if (x) MACRO() {} } " ) , InternalError ) ;
// #4810 - note there is no semicolon after MACRO()
ASSERT_THROW ( checkCode ( " void f() { if (x) MACRO() else ; } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void wrong_syntax_class_x_y ( ) {
2014-09-24 13:45:56 +02:00
// #3585
const char code [ ] = " class x y { }; " ;
2015-07-16 00:29:48 +02:00
{
errout . str ( " " ) ;
Settings settings ;
settings . addEnabled ( " information " ) ;
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
tokenizer . tokenize ( istr , " test.c " ) ;
tokenizer . simplifyTokenList2 ( ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
{
errout . str ( " " ) ;
Settings settings ;
settings . addEnabled ( " information " ) ;
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
tokenizer . tokenize ( istr , " test.cpp " ) ;
tokenizer . simplifyTokenList2 ( ) ;
ASSERT_EQUALS ( " [test.cpp:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code. \n " , errout . str ( ) ) ;
}
2014-09-24 13:45:56 +02:00
}
2014-11-20 14:20:09 +01:00
void syntax_case_default ( ) {
2014-09-24 13:45:56 +02:00
ASSERT_THROW ( checkCode ( " void f() {switch (n) { case: z(); break;}} " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() {switch (n) { case;: z(); break;}} " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() {switch (n) { case {}: z(); break;}} " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() {switch (n) { case 0?{1}:{2} : z(); break;}} " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() {switch (n) { case 0?1;:{2} : z(); break;}} " ) , InternalError ) ;
2015-05-01 18:28:00 +02:00
checkCode ( " void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}} " ) ;
2014-09-24 13:45:56 +02:00
//ticket #4234
ASSERT_THROW ( checkCode ( " ( ) { switch break ; { switch ( x ) { case } y break ; : } } " ) , InternalError ) ;
//ticket #4267
ASSERT_THROW ( checkCode ( " f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode1 ( ) {
2014-09-24 13:45:56 +02:00
checkCode ( " struct x foo_t; foo_t typedef y; " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode2 ( ) { //#4300 (segmentation fault)
2014-09-24 13:45:56 +02:00
ASSERT_THROW ( checkCode ( " enum { D = 1 struct { } ; } s.b = D; " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode3 ( ) { //#4849 (segmentation fault in Tokenizer::simplifyStructDecl (invalid code))
2014-09-24 13:45:56 +02:00
ASSERT_THROW ( checkCode ( " enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode4 ( ) { // #4887
2014-09-24 13:45:56 +02:00
ASSERT_THROW ( checkCode ( " void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode5 ( ) { // #5168
2014-09-24 13:45:56 +02:00
checkCode ( " ( asm : ; void : ); " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode6 ( ) { // #5214
2014-09-24 13:45:56 +02:00
checkCode ( " int b = ( 0 ? ? ) 1 : 0 ; " ) ;
checkCode ( " int a = int b = ( 0 ? ? ) 1 : 0 ; " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode7 ( ) {
2015-04-13 20:18:07 +02:00
checkCode ( " 1 (int j) { return return (c) * sizeof } y[1]; " ) ;
2014-09-24 13:45:56 +02:00
checkCode ( " foo(Args&&...) fn void = { } auto template<typename... bar(Args&&...) " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode8 ( ) { // #5604
2014-09-24 13:45:56 +02:00
ASSERT_THROW ( checkCode ( " { enum struct : }; " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " int ScopedEnum{ template<typename T> { { e = T::error }; }; \n "
" ScopedEnum1<int> se1; { enum class E : T { e = 0 = e ScopedEnum2<void*> struct UnscopedEnum3 { T{ e = 4 }; }; \n "
" arr[(int) E::e]; }; UnscopedEnum3<int> e2 = f() \n "
" { { e = e1; T::error } int test1 ue2; g() { enum class E { e = T::error }; return E::e; } int test2 = } \n "
" namespace UnscopedEnum { template<typename T> struct UnscopedEnum1 { E{ e = T::error }; }; UnscopedEnum1<int> { enum E : { e = 0 }; }; \n "
" UnscopedEnum2<void*> ue3; template<typename T> struct UnscopedEnum3 { enum { }; }; int arr[E::e]; }; \n "
" UnscopedEnum3<int> namespace template<typename T> int f() { enum E { e }; T::error }; return (int) E(); } int test1 int g() { enum E { e = E }; \n "
" E::e; } int test2 = g<int>(); } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode9 ( ) {
2014-09-24 13:45:56 +02:00
ASSERT_THROW ( checkCode ( " enum { e = { } } ( ) { { enum { } } } { e } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode10 ( ) { // #6127
2014-09-24 13:45:56 +02:00
checkCode ( " for( rl=reslist; rl!=NULL; rl=rl->next ) " ) ;
}
2014-09-28 22:05:05 +02:00
2014-11-20 14:20:09 +01:00
void garbageCode11 ( ) { // do not crash
2014-09-28 22:04:25 +02:00
checkCode ( " ( ) & " ) ;
}
2014-09-24 13:45:56 +02:00
2014-11-20 14:20:09 +01:00
void garbageCode12 ( ) { // do not crash
2014-09-29 19:44:25 +02:00
checkCode ( " { g; S (void) { struct } { } int &g; } " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode13 ( ) {
2014-10-16 10:59:46 +02:00
checkCode ( " struct C {} {} x " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode14 ( ) {
2014-10-16 10:59:46 +02:00
checkCode ( " static f() { int i; int source[1] = { 1 }; for (i = 0; i < 4; i++) (u, if (y u.x e)) } " ) ; // Garbage code
}
2014-11-20 14:20:09 +01:00
void garbageCode15 ( ) { // Ticket #5203
2014-10-16 10:59:46 +02:00
checkCode ( " int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } } " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode16 ( ) {
2014-10-16 10:59:46 +02:00
checkCode ( " { } A() { delete } " ) ; // #6080
}
2014-11-20 14:20:09 +01:00
void garbageCode17 ( ) {
2014-10-16 10:59:46 +02:00
ASSERT_THROW ( checkCode ( " void h(int l) { \n "
" while \n " // Don't crash (#3870)
" } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode18 ( ) {
2014-10-16 10:59:46 +02:00
ASSERT_THROW ( checkCode ( " switch(){case} " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode19 ( ) {
2014-10-16 10:59:46 +02:00
// ticket #3512 - Don't crash on garbage code
ASSERT_EQUALS ( " p = const " , checkCode ( " 1 *p = const " ) ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode20 ( ) {
2014-10-16 10:59:46 +02:00
// #3953 (valgrind errors on garbage code)
ASSERT_EQUALS ( " void f ( 0 * ) ; " , checkCode ( " void f ( 0 * ) ; " ) ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode21 ( ) {
2014-10-16 10:59:46 +02:00
// Ticket #3486 - Don't crash garbage code
checkCode ( " void f() \n "
" { \n "
" ( \n "
" x; \n "
" int a, a2, a2*x; if () ; \n "
" ) \n "
" } " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode22 ( ) {
2014-10-16 10:59:46 +02:00
// Ticket #3480 - Don't crash garbage code
ASSERT_THROW ( checkCode ( " int f() \n "
" { \n "
" return if \n "
" } " ) , InternalError ) ;
}
2014-11-20 14:20:09 +01:00
void garbageCode23 ( ) {
2014-10-16 10:59:46 +02:00
//garbage code : don't crash (#3481)
checkCode ( " { \n "
" if (1) = x \n "
" else abort s[2] \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2015-01-07 16:24:33 +01:00
void garbageCode24 ( ) {
// don't crash (example from #6361)
checkCode ( " float buffer[64]; \n "
" main (void) \n "
" { \n "
" char *cptr; \n "
" cptr = (char *)buffer; \n "
" cptr += (-(long int) buffer & (16 * sizeof (float) - 1)); \n "
" } \n " ) ;
}
2015-01-21 10:04:24 +01:00
void garbageCode25 ( ) {
// Ticket #2386 - Segmentation fault upon strange syntax
ASSERT_THROW ( checkCode ( " void f() { \n "
" switch ( x ) { \n "
" case struct Tree : break; \n "
" } \n "
" } " ) , InternalError ) ;
}
void garbageCode26 ( ) {
// See tickets #2518 #2555 #4171
ASSERT_THROW ( checkCode ( " void f() { \n "
" switch MAKEWORD(1) \n "
" { \n "
" case 0: \n "
" return; \n "
" } \n "
" } " ) , InternalError ) ;
}
void garbageCode27 ( ) {
ASSERT_THROW ( checkCode ( " int f() { \n "
" return if \n "
" } " ) , InternalError ) ;
}
void garbageCode28 ( ) {
// 5702
2015-04-06 19:47:21 +02:00
checkCode ( " struct R1 { \n "
" int a; \n "
" R1 () : a { } \n "
" }; \n " ) ;
2015-01-21 10:04:24 +01:00
}
2015-01-31 20:12:02 +01:00
void garbageCode29 ( ) {
// ticket #2601 segmentation fault
checkCode ( " || #if #define <= " ) ;
}
2015-02-22 13:09:39 +01:00
void garbageCode30 ( ) {
// simply survive - a syntax error would be even better (#5867)
checkCode ( " void f(int x) { \n "
" x = 42 \n "
" } " ) ;
}
2015-02-24 11:15:23 +01:00
void garbageCode31 ( ) {
ASSERT_THROW ( checkCode ( " typedef struct{}x[([],)]typedef e y;(y,x 0){} " ) , InternalError ) ;
}
2015-03-30 15:33:24 +02:00
void garbageCode32 ( ) { // #6135
checkCode ( " ( * const ( size_t ) ; foo ) " ) ;
}
2015-04-01 12:43:03 +02:00
void garbageCode33 ( ) { // #6613
ASSERT_THROW ( checkCode ( " main(()B{}); " ) , InternalError ) ;
checkCode ( " f::y:y : <x:: " ) ;
checkCode ( " \xe2 u. " ) ;
}
2015-04-06 17:23:48 +02:00
// Bug #6626 crash: Token::astOperand2() const ( do while )
void garbageCode34 ( ) {
checkCode ( " void foo(void) { \n "
" do \n "
" while (0); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2015-04-13 20:18:07 +02:00
void garbageCode35 ( ) {
// ticket #2599 segmentation fault
checkCode ( " sizeof " ) ;
// ticket #2604 segmentation fault
checkCode ( " sizeof <= A " ) ;
}
2015-05-07 20:34:57 +02:00
void garbageCode36 ( ) { // #6334
checkCode ( " { } < class template < > , { = } ; class... > \n "
" struct Y { } \n "
" class Types { } \n "
" ( X < int > \" uses template \" ) ( < ( ) \" uses ; \n "
" ( int int ::primary \" uses template \" ) int double \" uses ) \n "
" ::primary , \" uses template \" ; \n " ) ;
}
void garbageCode37 ( ) {
// #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } )
checkCode ( " void * f { } void b ( ) { * f } " ) ;
}
2015-05-10 10:00:46 +02:00
void garbageCode38 ( ) { // Ticket #6666
checkCode ( " { f2 { } } void f3 () { delete[] } { } " ) ;
}
2015-05-13 13:02:33 +02:00
void garbageCode39 ( ) { // #6686
checkCode ( " ({ (); strcat(strcat(() ()) ()) }) " ) ;
}
2015-05-22 22:18:42 +02:00
void garbageCode40 ( ) { // #6620
2015-05-26 00:28:08 +02:00
checkCode ( " { ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { } " ) ;
2015-06-30 12:16:55 +02:00
// test doesn't seem to work on any platform: ASSERT_THROW(checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }", "test.c"), InternalError);
2015-05-22 22:18:42 +02:00
}
void garbageCode41 ( ) { // #6685
2015-05-26 00:28:08 +02:00
checkCode ( " { } { return } *malloc(__SIZE_TYPE__ size); *memcpy(void n); static * const () { memcpy (*slot, 3); } { (); } { } " ) ;
2015-05-22 22:18:42 +02:00
}
2015-05-23 20:29:44 +02:00
void garbageCode42 ( ) { // #5760
2015-05-26 00:28:08 +02:00
checkCode ( " { } * const ( ) { } " ) ;
2015-05-23 20:29:44 +02:00
}
2015-05-23 23:18:59 +02:00
void garbageCode43 ( ) { // #6703
checkCode ( " int { }; struct A<void> a = { } " ) ;
}
2015-05-24 08:16:34 +02:00
void garbageCode44 ( ) { // #6704
ASSERT_THROW ( checkCode ( " { { }; }; { class A : }; public typedef b; " ) , InternalError ) ;
}
2015-05-24 10:03:50 +02:00
void garbageCode45 ( ) { // #6608
checkCode ( " struct true template < > { = } > struct Types \" s \" ; static_assert < int > ; " ) ;
}
2015-05-27 21:12:33 +02:00
void garbageCode46 ( ) { // #6705
checkCode ( " { bar(char *x); void foo (int ...) { struct } va_list ap; va_start(ap, size); va_arg(ap, (d)); } " ) ;
}
2015-05-27 21:39:31 +02:00
void garbageCode47 ( ) { // #6706
checkCode ( " { { }; }; * new private: B: B; " ) ;
}
2015-05-28 21:12:02 +02:00
void garbageCode48 ( ) { // #6712
checkCode ( " { d \n \" ) d ... \n \" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \" \" } } " ) ;
}
2015-05-28 21:38:20 +02:00
void garbageCode49 ( ) { // #6715
ASSERT_THROW ( checkCode ( " ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) } " ) , InternalError ) ;
}
2015-05-29 19:15:41 +02:00
void garbageCode50 ( ) { // #6718
2015-05-29 18:34:00 +02:00
checkCode ( " enum struct " ) ;
}
2015-05-29 19:15:41 +02:00
void garbageCode51 ( ) { // #6719
2015-05-29 18:34:00 +02:00
checkCode ( " (const \" C \" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = } " ) ;
}
2015-05-29 20:20:05 +02:00
void garbageCode52 ( ) { // #6720
2015-05-29 19:30:55 +02:00
checkCode ( " a \" b \" not_eq \" c \" " ) ;
}
2015-05-29 20:20:05 +02:00
void garbageCode53 ( ) { // #6721
2015-05-29 19:30:55 +02:00
checkCode ( " { { } }; void foo (struct int i) { x->b[i] = = } " ) ;
}
2015-05-29 21:44:00 +02:00
void garbageCode54 ( ) { // #6722
ASSERT_THROW ( checkCode ( " { typedef long ((pf) p) (); } " ) , InternalError ) ;
}
2015-05-30 19:15:53 +02:00
void garbageCode55 ( ) { // #6724
checkCode ( " () __attribute__((constructor)); { } { } " ) ;
}
2015-05-30 20:55:36 +02:00
void garbageCode56 ( ) { // #6713
checkCode ( " void foo() { int a = 0; int b = ???; } " ) ;
}
2015-06-01 13:27:32 +02:00
void garbageCode57 ( ) { // #6731
ASSERT_THROW ( checkCode ( " { } if () try { } catch (...) B::~B { } " ) , InternalError ) ;
}
2015-06-07 13:35:51 +02:00
void garbageCode58 ( ) { // #6732, #6762
2015-06-24 21:03:02 +02:00
ASSERT_THROW ( checkCode ( " { }> {= ~A()^{} }P { } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " {= ~A()^{} }P { } { }> is " ) , InternalError ) ;
2015-06-01 13:46:13 +02:00
}
2015-06-01 22:09:56 +02:00
void garbageCode59 ( ) { // #6735
ASSERT_THROW ( checkCode ( " { { } }; char font8x8[256][8] " ) , InternalError ) ;
}
2015-06-01 21:47:06 +02:00
2015-06-01 22:09:56 +02:00
void garbageCode60 ( ) { // #6736
ASSERT_THROW ( checkCode ( " { } { } typedef int int_array[]; int_array &right = " ) , InternalError ) ;
}
2015-06-01 21:47:06 +02:00
2015-06-02 18:28:43 +02:00
void garbageCode61 ( ) { // #6737
ASSERT_THROW ( checkCode ( " { (const U&) }; { }; { }; struct U : virtual public " ) , InternalError ) ;
}
2015-06-02 19:07:26 +02:00
void garbageCode62 ( ) { // #6738
checkCode ( " (int arg2) { } { } typedef void (func_type) (int, int); typedef func_type& " ) ;
}
2015-06-02 19:40:20 +02:00
void garbageCode63 ( ) { // #6739
2015-06-02 19:48:20 +02:00
ASSERT_THROW ( checkCode ( " { } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref u_array_ref_gbl_obj0 " ) , InternalError ) ;
}
void garbageCode64 ( ) { // #6740
ASSERT_THROW ( checkCode ( " { } foo(void (*bar)(void)) " ) , InternalError ) ;
2015-06-02 19:40:20 +02:00
}
2015-06-02 20:09:12 +02:00
void garbageCode65 ( ) { // #6741
ASSERT_THROW ( checkCode ( " { } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref " ) , InternalError ) ;
}
2015-06-02 20:15:21 +02:00
void garbageCode66 ( ) { // #6742
ASSERT_THROW ( checkCode ( " { { } }; { { } }; { }; class bar : public virtual " ) , InternalError ) ;
}
2015-06-02 21:20:41 +02:00
void garbageCode67 ( ) { // #6744
checkCode ( " &g[0]; { (g[0] 0) } = " , " test.c " ) ;
}
void garbageCode68 ( ) { // #6745
checkCode ( " (int a[3]); typedef void (*fp) (void); fp " ) ;
}
2015-06-02 21:52:08 +02:00
void garbageCode69 ( ) { // #6746
ASSERT_THROW ( checkCode ( " { (make_mess, aux); } typedef void F(void); aux(void (*x)()) { } (void (*y)()) { } F* " ) , InternalError ) ;
}
2015-06-01 13:46:13 +02:00
2015-06-02 22:26:17 +02:00
void garbageCode70 ( ) { // #6747
ASSERT_THROW ( checkCode ( " { } __attribute__((constructor)) void " ) , InternalError ) ;
}
2015-06-03 08:59:38 +02:00
void garbageCode71 ( ) { // #6748
ASSERT_THROW ( checkCode ( " ( ) { } typedef void noattr_t ( ) ; noattr_t __attribute__ ( ) " ) , InternalError ) ;
}
2015-06-03 10:39:19 +02:00
void garbageCode72 ( ) { // #6749
ASSERT_THROW ( checkCode ( " { } { } typedef void voidfn(void); <voidfn& " ) , InternalError ) ;
}
void garbageCode73 ( ) { // #6750
ASSERT_THROW ( checkCode ( " typedef int IRT[2]; IRT& " ) , InternalError ) ;
}
2015-06-03 11:39:30 +02:00
void garbageCode74 ( ) { // #6751
checkCode ( " _lenraw(const char* digits) { } typedef decltype(sizeof(0)) { } operator " ) ;
}
2015-06-03 17:17:53 +02:00
void garbageCode75 ( ) { // #6753
checkCode ( " { { void foo() { struct }; { }; } }; struct S { } f = " , " test.c " ) ;
}
void garbageCode76 ( ) { // #6754
checkCode ( " ( ) ( ) { ( ) [ ] } TEST ( ) { ( _broadcast_f32x4 ) ( ) ( ) ( ) ( ) if ( ) ( ) ; } E mask = ( ) [ ] ( ) res1.x = " ) ;
}
2015-06-05 14:34:53 +02:00
void garbageCode77 ( ) { // #6755
2015-06-04 17:45:12 +02:00
checkCode ( " void foo (int **p) { { { };>= } } unsigned *d = (b b--) --*d " ) ;
}
2015-06-05 14:34:53 +02:00
void garbageCode78 ( ) { // #6756
2015-06-04 17:45:12 +02:00
checkCode ( " ( ) { [ ] } ( ) { } const_array_of_int ( ) { } typedef int A [ ] [ ] ; A a = { { } { } } " ) ;
}
2015-06-05 14:34:53 +02:00
void garbageCode79 ( ) { // #6757
2015-06-04 19:00:35 +02:00
ASSERT_THROW ( checkCode ( " { } { } typedef void ( func_type ) ( ) ; func_type & ( ) " ) , InternalError ) ;
}
2015-06-06 13:11:32 +02:00
void garbageCode80 ( ) { // #6759
ASSERT_THROW ( checkCode ( " ( ) { ; ( ) ; ( * ) [ ] ; [ ] = ( ( ) ( ) h ) ! ( ( ) ) } { ; } { } head heads [ ] = ; = & heads [ 2 ] " ) , InternalError ) ;
}
void garbageCode81 ( ) { // #6760
ASSERT_THROW ( checkCode ( " { } [ ] { ( ) } { } typedef void ( *fptr1 ) ( ) const " ) , InternalError ) ;
}
2015-06-07 13:35:51 +02:00
void garbageCode82 ( ) { // #6761
ASSERT_THROW ( checkCode ( " p( \" Hello \" 14) _yn(const size_t) typedef bool pfunk (*pfunk)(const size_t) " ) , InternalError ) ;
}
2015-06-14 22:18:28 +02:00
void garbageCode83 ( ) { // #6771
ASSERT_THROW ( checkCode ( " namespace A { class } class A { friend C ; } { } ; " ) , InternalError ) ;
}
2015-06-22 11:12:46 +02:00
void garbageCode84 ( ) { // #6780
checkCode ( " int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { } " ) ; // do not crash
}
2015-06-22 20:43:26 +02:00
void garbageCode85 ( ) { // #6784
ASSERT_THROW ( checkCode ( " { } { } typedef void ( *VoidFunc() ) ( ) ; VoidFunc " ) , InternalError ) ; // do not crash
}
2015-06-23 17:59:01 +02:00
void garbageCode86 ( ) { // #6785
ASSERT_THROW ( checkCode ( " { } typedef char ( *( X ) ( void) , char ) ; " ) , InternalError ) ; // do not crash
}
2015-06-24 16:54:23 +02:00
void garbageCode87 ( ) { // #6788
ASSERT_THROW ( checkCode ( " ((X (128))) (int a) { v[ = {} (x 42) a] += } " ) , InternalError ) ; // do not crash
}
2015-06-24 20:22:28 +02:00
void garbageCode88 ( ) { // #6786
ASSERT_THROW ( checkCode ( " ( ) { ( 0 ) { ( ) } } g ( ) { i( ( false ?) ( ) : 1 ) ; } ; " ) , InternalError ) ; // do not crash
}
2015-06-24 20:47:04 +02:00
void garbageCode89 ( ) { // #6772
ASSERT_THROW ( checkCode ( " { { ( ) } P ( ) ^ { } { } { } ( ) } 0 " ) , InternalError ) ; // do not crash
}
2015-06-25 07:47:40 +02:00
void garbageCode90 ( ) { // #6790
ASSERT_THROW ( checkCode ( " { } { } typedef int u_array [[ ] ; typedef u_array & u_array_ref] ( ) { } u_array_ref_gbl_obj0 " ) , InternalError ) ; // do not crash
}
2015-06-25 08:57:09 +02:00
void garbageCode91 ( ) { // #6791
checkCode ( " typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] } " ) ; // do not crash
}
2015-06-25 20:48:05 +02:00
void garbageCode92 ( ) { // #6792
ASSERT_THROW ( checkCode ( " template < typename _Tp ( ( ) ; _Tp ) , decltype > { } { ( ) ( ) } " ) , InternalError ) ; // do not crash
}
2015-06-29 19:56:02 +02:00
void garbageCode93 ( ) { // #6800
checkCode ( " namespace A { } class A{ { }} class A : T ; " , " test.c " ) ; // do not crash
}
2015-06-30 12:16:55 +02:00
void garbageCode94 ( ) { // #6803
//checkCode("typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; }");
ASSERT_THROW ( checkCode ( " typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; } " ) , InternalError ) ;
}
2015-06-30 19:40:22 +02:00
void garbageCode95 ( ) { // #6804
2015-07-01 07:50:13 +02:00
checkCode ( " { } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } } " ) ; // do not crash
2015-06-30 19:40:22 +02:00
}
2015-07-01 16:31:49 +02:00
void garbageCode96 ( ) { // #6807
ASSERT_THROW ( checkCode ( " typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ; " ) , InternalError ) ;
}
void garbageCode97 ( ) { // #6808
ASSERT_THROW ( checkCode ( " namespace A {> } class A{ { }} class A : T< ; " ) , InternalError ) ;
}
2015-07-14 21:07:10 +02:00
void garbageCode98 ( ) { // #6838
ASSERT_THROW ( checkCode ( " for (cocon To::ta@Taaaaaforconst oken aaaaaaaaaaaa5Dl() \n "
" const unsiged in; \n "
" fon *tok = f);.s(Token i = d-)L; " ) , InternalError ) ;
}
2015-07-15 15:18:22 +02:00
void garbageCode99 ( ) { // #6726
ASSERT_THROW ( checkCode ( " { xs :: i(:) ! ! x/5 ! ! \n "
" i, :: a :: b integer, } foo2(x) :: j(:) \n "
" b type(*), d(:), a x :: end d(..), foo end \n "
" foo4 b d(..), a a x type(*), b foo2 b " ) , InternalError ) ;
}
void garbageCode100 ( ) { // #6840
checkCode ( " ( ) { ( i< ) } int foo ( ) { int i ; ( for ( i => 1 ) ; ) } " ) ;
}
2015-07-17 21:30:34 +02:00
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<void> a; " ) ;
}
2015-07-20 19:04:34 +02:00
void garbageCode102 ( ) { // #6846
checkCode ( " struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } } " ) ;
}
2015-07-20 22:33:32 +02:00
void garbageCode103 ( ) { // #6824
ASSERT_THROW ( checkCode ( " a f(r) int * r; { { int s[2]; [f(s); if () ] } } " ) , InternalError ) ;
}
2015-07-21 13:40:50 +02:00
void garbageCode104 ( ) { // #6847
ASSERT_THROW ( checkCode ( " template < Types > struct S {> ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } { ( )> >} { ( ) { } } ( ) { ( ) } " ) , InternalError ) ;
}
2015-07-22 13:32:34 +02:00
void garbageCode105 ( ) { // #6859
checkCode ( " void foo (int i) { int a , for (a 1; a( < 4; a++) if (a) (b b++) (b);) n++; } " ) ;
}
2014-11-20 14:20:09 +01:00
void garbageValueFlow ( ) {
2014-10-16 10:59:46 +02:00
// #6089
const char * code = " {} int foo(struct, x1, struct x2, x3, int, x5, x6, x7) \n "
" { \n "
" (foo(s, , 2, , , 5, , 7)) abort() \n "
" } \n " ;
2015-01-31 10:33:15 +01:00
checkCode ( code ) ;
2014-10-16 10:59:46 +02:00
// #6106
code = " f { int i ; b2 , [ ] ( for ( i = 0 ; ; ) ) } " ;
checkCode ( code ) ;
// 6122 survive garbage code
code = " ; { int i ; for ( i = 0 ; = 123 ; ) - ; } " ;
checkCode ( code ) ;
2015-02-01 12:26:46 +01:00
code = " void f1() { for (int n = 0 n < 10 n++); } " ;
checkCode ( code ) ;
2014-10-16 10:59:46 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageSymbolDatabase ( ) {
2014-10-16 10:59:46 +02:00
checkCode ( " void f( { u = 1 ; } ) { } " ) ;
checkCode ( " { }; void namespace A::f; { g() { int } } " ) ;
ASSERT_THROW ( checkCode ( " class Foo {}; class Bar : public Foo " ) , InternalError ) ;
2015-02-24 06:11:31 +01:00
checkCode ( " YY_DECL { switch (yy_act) { \n "
" case 65: YY_BREAK \n "
" case YY_STATE_EOF(block): \n "
" yyterminate(); \n "
" } } " ) ; // #5663
2014-10-16 10:59:46 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageAST ( ) {
2014-09-24 13:45:56 +02:00
checkCode ( " -- " ) ; // don't crash
checkCode ( " N 1024 float a[N], b[N + 3], c[N]; void N; (void) i; \n "
" int #define for (i = avx_test i < c[i]; i++) \n "
" b[i + 3] = a[i] * {} " ) ; // Don't hang (#5787)
checkCode ( " START_SECTION([EXTRA](bool isValid(const String &filename))) " ) ; // Don't crash (#5991)
}
2015-01-18 13:13:52 +01:00
void templateSimplifierCrashes ( ) {
checkCode ( //5950
" struct A { \n "
" template <class T> operator T*(); \n "
" }; \n "
" \n "
" template <> A::operator char*(){ return 0; } // specialization \n "
" \n "
" int main() { \n "
" A a; \n "
" int *ip = a.operator int*(); \n "
" } \n "
" \n "
" namespace PR5742 { \n "
" template <class T> struct A { }; \n "
" struct S { \n "
" template <class T> operator T(); \n "
" } s; \n "
" void f() { \n "
" s.operator A<A<int> >(); \n "
" } \n "
" } \n " ) ;
checkCode ( // 6034
" template<template<typename...> class T, typename... Args> \n "
" struct foo<T<Args...> > { \n "
" const bool value = true; \n "
" }; \n "
" \n "
" template<int I> \n "
" struct int_ \n "
" {}; \n "
" \n "
" int main() { \n "
" foo<int_<0> >::value; \n "
" } \n "
) ;
checkCode ( " > template < . > struct Y < T > { = } ; \n " ) ; //6108
checkCode ( // 6117
" template <typename ...> struct something_like_tuple \n "
" {}; \n "
" template <typename, typename> struct is_last { \n "
" static const bool value = false; \n "
" }; \n "
" template <typename T, template <typename ...> class Tuple, typename ... Head> \n "
" struct is_last<T, Tuple<Head ..., T>> \n "
" { \n "
" static const bool value = true; \n "
" }; \n "
" \n "
" #define SA(X) static_assert (X, #X) \n "
" \n "
" typedef something_like_tuple<char, int, float> something_like_tuple_t; \n "
" SA ((is_last<float, something_like_tuple_t>::value == false)); \n "
" SA ((is_last<int, something_like_tuple_t>::value == false)); \n "
) ;
checkCode ( //6225
" template <typename...> \n "
" void templ_fun_with_ty_pack() {} \n "
" \n "
" namespace PR20047 { \n "
" template <typename T> \n "
" struct A {}; \n "
" using AliasA = A<T>; \n "
" } \n "
) ;
}
2014-09-24 13:45:56 +02:00
} ;
REGISTER_TEST ( TestGarbage )