2014-09-24 13:45:56 +02:00
/*
* Cppcheck - A tool for static C / C + + code analysis
2023-01-28 10:16:34 +01:00
* Copyright ( C ) 2007 - 2023 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/>.
*/
2017-05-27 04:33:47 +02:00
# include "check.h"
2022-01-27 19:03:20 +01:00
# include "errortypes.h"
# include "mathlib.h"
2023-03-02 21:48:14 +01:00
# include "preprocessor.h"
2017-05-27 04:33:47 +02:00
# include "settings.h"
2023-01-27 08:18:32 +01:00
# include "fixture.h"
2014-09-24 13:45:56 +02:00
# include "token.h"
2017-05-27 04:33:47 +02:00
# include "tokenize.h"
# include <list>
2022-09-16 07:15:49 +02:00
# include <sstream> // IWYU pragma: keep
2022-01-27 19:03:20 +01:00
# include <string>
2014-09-24 13:45:56 +02:00
class TestGarbage : public TestFixture {
public :
2021-08-07 20:51:18 +02:00
TestGarbage ( ) : TestFixture ( " TestGarbage " ) { }
2014-09-24 13:45:56 +02:00
private :
2023-05-02 15:54:19 +02:00
Settings settings = settingsBuilder ( ) . debugwarnings ( ) . build ( ) ;
2014-09-24 13:45:56 +02:00
2022-02-10 23:02:24 +01:00
void run ( ) override {
2021-02-24 22:00:06 +01:00
settings . severity . fill ( ) ;
settings . certainty . fill ( ) ;
2015-10-07 18:33:57 +02:00
2014-09-24 13:45:56 +02:00
// don't freak out when the syntax is wrong
2019-08-23 10:19:29 +02:00
2019-08-23 06:43:02 +02:00
TEST_CASE ( final_class_x ) ;
2014-09-24 13:45:56 +02:00
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 { };
2021-05-08 15:28:21 +02:00
TEST_CASE ( wrong_syntax_anonymous_struct ) ;
2014-09-24 13:45:56 +02:00
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
2015-08-16 14:48:56 +02:00
TEST_CASE ( garbageCode10 ) ; // #6127
2014-09-29 19:44:25 +02:00
TEST_CASE ( garbageCode12 ) ;
2015-08-16 14:48:56 +02:00
TEST_CASE ( garbageCode13 ) ; // #2607
TEST_CASE ( garbageCode15 ) ; // #5203
2014-10-16 10:59:46 +02:00
TEST_CASE ( garbageCode16 ) ;
TEST_CASE ( garbageCode17 ) ;
TEST_CASE ( garbageCode18 ) ;
TEST_CASE ( garbageCode20 ) ;
TEST_CASE ( garbageCode21 ) ;
TEST_CASE ( garbageCode22 ) ;
TEST_CASE ( garbageCode23 ) ;
2015-08-16 14:48:56 +02:00
TEST_CASE ( garbageCode24 ) ; // #6361
2015-01-21 10:04:24 +01:00
TEST_CASE ( garbageCode25 ) ;
TEST_CASE ( garbageCode26 ) ;
TEST_CASE ( garbageCode27 ) ;
TEST_CASE ( garbageCode28 ) ;
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-04-01 12:43:03 +02:00
TEST_CASE ( garbageCode33 ) ; // #6613
2015-04-13 20:18:07 +02:00
TEST_CASE ( garbageCode34 ) ; // #6626
2016-11-21 13:54:59 +01:00
TEST_CASE ( garbageCode35 ) ; // #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-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 ( garbageCode51 ) ; // #6719
2015-05-29 20:20:05 +02:00
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: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 ( 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 ( 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-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-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
2015-07-28 18:41:50 +02:00
TEST_CASE ( garbageCode106 ) ;
TEST_CASE ( garbageCode107 ) ;
2015-07-30 17:19:19 +02:00
TEST_CASE ( garbageCode108 ) ;
2015-07-31 20:24:06 +02:00
TEST_CASE ( garbageCode109 ) ;
TEST_CASE ( garbageCode110 ) ;
2015-08-01 07:39:56 +02:00
TEST_CASE ( garbageCode111 ) ;
2015-08-01 12:31:16 +02:00
TEST_CASE ( garbageCode112 ) ;
2019-08-27 06:37:58 +02:00
TEST_CASE ( garbageCode114 ) ; // #2118
2015-08-16 14:48:56 +02:00
TEST_CASE ( garbageCode115 ) ; // #5506
TEST_CASE ( garbageCode116 ) ; // #5356
TEST_CASE ( garbageCode117 ) ; // #6121
TEST_CASE ( garbageCode118 ) ; // #5600
2015-08-16 19:11:56 +02:00
TEST_CASE ( garbageCode119 ) ; // #5598
TEST_CASE ( garbageCode120 ) ; // #4927
TEST_CASE ( garbageCode121 ) ; // #2585
TEST_CASE ( garbageCode122 ) ; // #6303
TEST_CASE ( garbageCode123 ) ;
2015-09-05 08:38:50 +02:00
TEST_CASE ( garbageCode125 ) ; // 6782, 6834
2015-09-23 10:33:55 +02:00
TEST_CASE ( garbageCode126 ) ; // #6997
2015-09-30 21:55:32 +02:00
TEST_CASE ( garbageCode127 ) ; // #6667
2015-10-02 15:33:23 +02:00
TEST_CASE ( garbageCode128 ) ; // #7018
2015-10-03 10:47:23 +02:00
TEST_CASE ( garbageCode129 ) ; // #7020
TEST_CASE ( garbageCode130 ) ; // #7021
2015-10-06 11:21:31 +02:00
TEST_CASE ( garbageCode131 ) ; // #7023
2015-10-07 13:52:06 +02:00
TEST_CASE ( garbageCode132 ) ; // #7022
2015-10-07 22:45:38 +02:00
TEST_CASE ( garbageCode133 ) ;
2016-11-20 14:36:36 +01:00
TEST_CASE ( garbageCode134 ) ;
2015-10-08 11:35:51 +02:00
TEST_CASE ( garbageCode135 ) ; // #4994
2015-10-09 13:06:52 +02:00
TEST_CASE ( garbageCode136 ) ; // #7033
2015-10-09 13:49:17 +02:00
TEST_CASE ( garbageCode137 ) ; // #7034
2015-10-12 18:14:56 +02:00
TEST_CASE ( garbageCode138 ) ; // #6660
TEST_CASE ( garbageCode139 ) ; // #6659
TEST_CASE ( garbageCode140 ) ; // #7035
2015-10-14 20:34:55 +02:00
TEST_CASE ( garbageCode141 ) ; // #7043
2015-10-15 21:27:55 +02:00
TEST_CASE ( garbageCode142 ) ; // #7050
2015-10-18 11:52:25 +02:00
TEST_CASE ( garbageCode143 ) ; // #6922
2015-10-18 15:47:37 +02:00
TEST_CASE ( garbageCode144 ) ; // #6865
2015-10-31 18:10:42 +01:00
TEST_CASE ( garbageCode146 ) ; // #7081
2015-11-02 21:30:28 +01:00
TEST_CASE ( garbageCode147 ) ; // #7082
2015-11-04 10:10:20 +01:00
TEST_CASE ( garbageCode148 ) ; // #7090
2015-11-04 10:26:55 +01:00
TEST_CASE ( garbageCode149 ) ; // #7085
2015-11-05 19:00:08 +01:00
TEST_CASE ( garbageCode150 ) ; // #7089
2016-11-20 17:59:50 +01:00
TEST_CASE ( garbageCode151 ) ; // #4911
2015-11-07 20:43:58 +01:00
TEST_CASE ( garbageCode152 ) ; // travis after 9c7271a5
2015-11-08 13:45:55 +01:00
TEST_CASE ( garbageCode153 ) ;
2015-11-08 14:21:12 +01:00
TEST_CASE ( garbageCode154 ) ; // #7112
2015-11-09 17:25:20 +01:00
TEST_CASE ( garbageCode156 ) ; // #7120
2015-11-14 21:22:53 +01:00
TEST_CASE ( garbageCode157 ) ; // #7131
2015-11-21 20:24:30 +01:00
TEST_CASE ( garbageCode158 ) ; // #3238
2015-11-29 14:56:15 +01:00
TEST_CASE ( garbageCode159 ) ; // #7119
2015-12-05 13:55:33 +01:00
TEST_CASE ( garbageCode160 ) ; // #7190
2015-12-09 14:00:40 +01:00
TEST_CASE ( garbageCode161 ) ; // #7200
2015-12-12 15:39:38 +01:00
TEST_CASE ( garbageCode162 ) ; // #7208
2015-12-26 01:37:21 +01:00
TEST_CASE ( garbageCode163 ) ; // #7228
2015-12-26 23:51:10 +01:00
TEST_CASE ( garbageCode164 ) ; // #7234
TEST_CASE ( garbageCode165 ) ; // #7235
TEST_CASE ( garbageCode167 ) ; // #7237
2015-12-31 14:17:52 +01:00
TEST_CASE ( garbageCode168 ) ; // #7246
2016-01-01 23:32:10 +01:00
TEST_CASE ( garbageCode169 ) ; // #6731
2016-01-03 20:53:03 +01:00
TEST_CASE ( garbageCode170 ) ;
2016-01-08 15:24:05 +01:00
TEST_CASE ( garbageCode171 ) ;
2016-01-26 19:12:57 +01:00
TEST_CASE ( garbageCode172 ) ;
2016-01-30 18:20:45 +01:00
TEST_CASE ( garbageCode173 ) ; // #6781
2016-01-31 10:25:09 +01:00
TEST_CASE ( garbageCode174 ) ; // #7356
2016-01-31 22:16:58 +01:00
TEST_CASE ( garbageCode175 ) ;
2016-02-04 09:10:20 +01:00
TEST_CASE ( garbageCode176 ) ; // #7527
TEST_CASE ( garbageCode181 ) ;
2016-05-17 22:19:23 +02:00
TEST_CASE ( garbageCode182 ) ; // #4195
2016-05-25 13:14:34 +02:00
TEST_CASE ( garbageCode183 ) ; // #7505
2016-08-21 11:06:48 +02:00
TEST_CASE ( garbageCode184 ) ; // #7699
2017-01-08 02:36:21 +01:00
TEST_CASE ( garbageCode185 ) ; // #6011
2017-08-15 22:40:55 +02:00
TEST_CASE ( garbageCode186 ) ; // #8151
2017-08-15 23:18:46 +02:00
TEST_CASE ( garbageCode187 ) ;
2017-10-28 07:39:35 +02:00
TEST_CASE ( garbageCode188 ) ;
2018-01-07 12:52:28 +01:00
TEST_CASE ( garbageCode189 ) ; // #8317
2018-01-07 13:11:56 +01:00
TEST_CASE ( garbageCode190 ) ; // #8307
2018-01-18 08:51:35 +01:00
TEST_CASE ( garbageCode191 ) ; // #8333
2018-02-03 15:50:05 +01:00
TEST_CASE ( garbageCode192 ) ; // #8386 (segmentation fault)
2018-09-08 21:10:34 +02:00
TEST_CASE ( garbageCode193 ) ; // #8740
TEST_CASE ( garbageCode194 ) ; // #8384
2018-09-10 08:40:53 +02:00
TEST_CASE ( garbageCode195 ) ; // #8709
2018-09-10 16:17:44 +02:00
TEST_CASE ( garbageCode196 ) ; // #8265
2018-09-10 16:24:09 +02:00
TEST_CASE ( garbageCode197 ) ; // #8385
2018-09-10 16:28:32 +02:00
TEST_CASE ( garbageCode198 ) ; // #8383
2018-09-13 09:19:15 +02:00
TEST_CASE ( garbageCode199 ) ; // #8752
2018-10-28 17:17:53 +01:00
TEST_CASE ( garbageCode200 ) ; // #8757
2018-12-01 17:29:41 +01:00
TEST_CASE ( garbageCode201 ) ; // #8873
2019-01-01 19:30:13 +01:00
TEST_CASE ( garbageCode202 ) ; // #8907
2019-02-11 07:45:03 +01:00
TEST_CASE ( garbageCode203 ) ; // #8972
2019-06-03 07:06:04 +02:00
TEST_CASE ( garbageCode204 ) ;
2019-07-10 07:16:16 +02:00
TEST_CASE ( garbageCode205 ) ;
2019-11-09 18:00:21 +01:00
TEST_CASE ( garbageCode206 ) ;
2019-11-19 21:50:53 +01:00
TEST_CASE ( garbageCode207 ) ; // #8750
TEST_CASE ( garbageCode208 ) ; // #8753
TEST_CASE ( garbageCode209 ) ; // #8756
TEST_CASE ( garbageCode210 ) ; // #8762
TEST_CASE ( garbageCode211 ) ; // #8764
TEST_CASE ( garbageCode212 ) ; // #8765
2020-01-01 15:46:09 +01:00
TEST_CASE ( garbageCode213 ) ; // #8758
2020-04-09 17:42:51 +02:00
TEST_CASE ( garbageCode214 ) ;
2020-11-28 14:41:05 +01:00
TEST_CASE ( garbageCode215 ) ; // daca@home script with extension .c
2021-10-08 23:14:16 +02:00
TEST_CASE ( garbageCode216 ) ; // #7884
2021-11-16 16:01:10 +01:00
TEST_CASE ( garbageCode217 ) ; // #10011
2021-12-20 13:12:19 +01:00
TEST_CASE ( garbageCode218 ) ; // #8763
TEST_CASE ( garbageCode219 ) ; // #10101
2022-02-10 14:13:50 +01:00
TEST_CASE ( garbageCode220 ) ; // #6832
2022-02-15 20:19:03 +01:00
TEST_CASE ( garbageCode221 ) ;
2022-02-18 12:59:21 +01:00
TEST_CASE ( garbageCode222 ) ; // #10763
2023-03-28 11:24:52 +02:00
TEST_CASE ( garbageCode223 ) ; // #11639
2018-01-24 13:53:03 +01:00
TEST_CASE ( garbageCodeFuzzerClientMode1 ) ; // test cases created with the fuzzer client, mode 1
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 ) ;
2016-11-20 17:59:50 +01:00
TEST_CASE ( syntaxErrorFirstToken ) ; // Make sure syntax errors are detected and reported
TEST_CASE ( syntaxErrorLastToken ) ; // Make sure syntax errors are detected and reported
2017-09-15 22:37:31 +02:00
TEST_CASE ( syntaxErrorCase ) ;
2019-03-23 18:27:41 +01:00
TEST_CASE ( syntaxErrorFuzzerCliType1 ) ;
2019-04-19 13:55:25 +02:00
TEST_CASE ( cliCode ) ;
2017-05-25 09:50:14 +02:00
TEST_CASE ( enumTrailingComma ) ;
2018-03-24 07:28:02 +01:00
TEST_CASE ( nonGarbageCode1 ) ; // #8346
2014-09-24 13:45:56 +02:00
}
2021-11-29 07:34:39 +01:00
# define checkCodeInternal(code, filename) checkCodeInternal_(code, filename, __FILE__, __LINE__)
2017-08-15 23:18:46 +02:00
std : : string checkCode ( const std : : string & code , bool cpp = true ) {
2015-07-01 07:50:13 +02:00
// double the tests - run each example as C as well as C++
2016-01-26 19:12:57 +01:00
const char * const filename = cpp ? " test.cpp " : " test.c " ;
const char * const alternatefilename = cpp ? " test.c " : " test.cpp " ;
2015-08-16 19:11:56 +02:00
2016-01-26 19:12:57 +01:00
// run alternate check first. It should only ensure stability - so we catch exceptions here.
2015-07-01 07:50:13 +02:00
try {
checkCodeInternal ( code , alternatefilename ) ;
2021-08-07 20:51:18 +02:00
} catch ( const 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
2021-11-29 07:34:39 +01:00
std : : string checkCodeInternal_ ( const std : : string & code , const char * filename , const char * file , int line ) {
2014-09-24 13:45:56 +02:00
errout . str ( " " ) ;
2023-04-21 10:14:34 +02:00
Preprocessor preprocessor ( settings ) ;
2023-03-02 21:48:14 +01:00
2014-09-24 13:45:56 +02:00
// tokenize..
2023-03-02 21:48:14 +01:00
Tokenizer tokenizer ( & settings , this , & preprocessor ) ;
2014-09-24 13:45:56 +02:00
std : : istringstream istr ( code ) ;
2021-11-29 07:34:39 +01:00
ASSERT_LOC ( tokenizer . tokenize ( istr , filename ) , file , line ) ;
2014-09-24 13:45:56 +02:00
2014-09-30 08:54:27 +02:00
// call all "runChecks" in all registered Check classes
2022-12-20 20:32:16 +01:00
for ( std : : list < Check * > : : const_iterator it = Check : : instances ( ) . cbegin ( ) ; it ! = Check : : instances ( ) . cend ( ) ; + + it ) {
2023-08-18 12:03:50 +02:00
( * it ) - > runChecks ( tokenizer , this ) ;
2014-09-30 10:37:55 +02:00
}
2019-06-30 21:39:22 +02:00
return tokenizer . tokens ( ) - > stringifyList ( false , false , false , true , false , nullptr , nullptr ) ;
2014-09-24 13:45:56 +02:00
}
2021-11-29 07:34:39 +01:00
# define getSyntaxError(code) getSyntaxError_(code, __FILE__, __LINE__)
std : : string getSyntaxError_ ( const char code [ ] , const char * file , int line ) {
2019-01-05 11:56:21 +01:00
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
try {
2021-11-29 07:34:39 +01:00
ASSERT_LOC ( tokenizer . tokenize ( istr , " test.cpp " ) , file , line ) ;
2019-01-05 11:56:21 +01:00
} catch ( InternalError & e ) {
if ( e . id ! = " syntaxError " )
return " " ;
2023-08-17 16:46:32 +02:00
return " [test.cpp: " + std : : to_string ( e . token - > linenr ( ) ) + " ] " + e . errorMessage ;
2019-01-05 11:56:21 +01:00
}
return " " ;
}
2019-08-23 06:43:02 +02:00
void final_class_x ( ) {
2019-08-23 10:19:29 +02:00
const char code [ ] = " class __declspec(dllexport) x final { }; " ;
{
errout . str ( " " ) ;
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
2021-11-29 07:34:39 +01:00
ASSERT ( tokenizer . tokenize ( istr , " test.cpp " ) ) ;
2019-08-23 10:19:29 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2019-08-23 06:43:02 +02:00
}
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;)) " ;
2019-11-01 09:05:45 +01:00
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
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..
2017-12-29 22:47:07 +01:00
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
2019-08-23 06:43:02 +02:00
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 "
" } " ;
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
try {
2021-11-29 07:34:39 +01:00
ASSERT ( tokenizer . tokenize ( istr , " test.cpp " ) ) ;
2014-09-24 13:45:56 +02:00
assertThrowFail ( __FILE__ , __LINE__ ) ;
} catch ( InternalError & e ) {
2019-03-23 18:27:41 +01:00
ASSERT_EQUALS ( " syntax error " , e . errorMessage ) ;
ASSERT_EQUALS ( " syntaxError " , e . id ) ;
2017-08-25 17:17:19 +02:00
ASSERT_EQUALS ( 4 , e . token - > linenr ( ) ) ;
2014-09-24 13:45:56 +02:00
}
}
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 ( " " ) ;
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
2021-11-29 07:34:39 +01:00
ASSERT ( tokenizer . tokenize ( istr , " test.c " ) ) ;
2015-07-16 00:29:48 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
{
errout . str ( " " ) ;
Tokenizer tokenizer ( & settings , this ) ;
std : : istringstream istr ( code ) ;
2021-11-29 07:34:39 +01:00
ASSERT ( tokenizer . tokenize ( istr , " test.cpp " ) ) ;
2015-07-16 00:29:48 +02:00
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
}
2021-05-08 15:28:21 +02:00
void wrong_syntax_anonymous_struct ( ) {
ASSERT_THROW ( checkCode ( " struct { int x; } = {0}; " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " struct { int x; } * = {0}; " ) , InternalError ) ;
}
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 ) ;
2017-06-08 15:32:35 +02:00
ASSERT_THROW ( checkCode ( " void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}} " ) , InternalError ) ;
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 ) ;
2018-01-27 22:21:26 +01:00
// Missing semicolon
ASSERT_THROW ( checkCode ( " void foo () { switch(0) case 0 : default : } " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
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)
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { D = 1 struct { } ; } s.b = D; " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageCode3 ( ) { //#4849 (segmentation fault in Tokenizer::simplifyStructDecl (invalid code))
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; } " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
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
2015-10-12 18:14:56 +02:00
ASSERT_THROW ( checkCode ( " int b = ( 0 ? ? ) 1 : 0 ; " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " int a = int b = ( 0 ? ? ) 1 : 0 ; " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageCode7 ( ) {
2019-03-23 18:27:41 +01:00
ASSERT_THROW ( checkCode ( " 1 (int j) { return return (c) * sizeof } y[1]; " ) , InternalError ) ;
2017-12-29 22:47:07 +01:00
ASSERT_THROW ( checkCode ( " foo(Args&&...) fn void = { } auto template<typename... bar(Args&&...) " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageCode8 ( ) { // #5604
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " { enum struct : }; " ) , InternalError ) ;
TODO_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 "
2021-02-20 12:58:42 +01:00
" { { e = e1; T::error } int test1 ue2; g() { enum class E { e = T::error }; return E::e; } int test2 = } \n "
2016-04-22 06:02:54 +02:00
" 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-09-24 13:45:56 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageCode9 ( ) {
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { e = { } } ( ) { { enum { } } } { e } " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageCode10 ( ) { // #6127
2020-04-11 17:36:11 +02:00
ASSERT_THROW ( checkCode ( " for( rl=reslist; rl!=NULL; rl=rl->next ) " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
2014-09-28 22:05:05 +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 garbageCode15 ( ) { // Ticket #5203
2016-07-22 16:54:24 +02:00
ASSERT_THROW ( checkCode ( " int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } } " ) , InternalError ) ;
2014-10-16 10:59:46 +02:00
}
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 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
2016-07-22 16:54:24 +02:00
ASSERT_THROW ( checkCode ( " void f() \n "
" { \n "
" ( \n "
" x; \n "
" int a, a2, a2*x; if () ; \n "
" ) \n "
" } " ) , InternalError ) ;
2014-10-16 10:59:46 +02:00
}
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)
2023-06-17 18:39:23 +02:00
ASSERT_THROW_EQUALS ( checkCode ( " { \n "
" if (1) = x \n "
" else abort s[2] \n "
" } " ) ,
InternalError ,
" syntax error " ) ;
2014-10-16 10:59:46 +02:00
}
2015-01-07 16:24:33 +01:00
void garbageCode24 ( ) {
// don't crash (example from #6361)
2017-01-06 11:53:17 +01:00
ASSERT_THROW ( 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 " ) , InternalError ) ;
2015-01-07 16:24:33 +01:00
}
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 "
2021-02-20 12:58:42 +01:00
" }; " ) ;
2015-01-21 10:04:24 +01:00
}
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-04-01 12:43:03 +02:00
void garbageCode33 ( ) { // #6613
2016-01-03 22:52:24 +01:00
checkCode ( " main(()B{}); " ) ;
2015-04-01 12:43:03 +02:00
}
2015-04-06 17:23:48 +02:00
// Bug #6626 crash: Token::astOperand2() const ( do while )
void garbageCode34 ( ) {
2015-09-23 10:33:55 +02:00
const char code [ ] = " void foo(void) { \n "
" do \n "
" while (0); \n "
" } " ;
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
2015-04-06 17:23:48 +02:00
}
2015-04-13 20:18:07 +02:00
void garbageCode35 ( ) {
// ticket #2604 segmentation fault
2018-10-13 18:38:44 +02:00
ASSERT_THROW ( checkCode ( " sizeof <= A " ) , InternalError ) ;
2015-04-13 20:18:07 +02:00
}
2015-05-07 20:34:57 +02:00
void garbageCode36 ( ) { // #6334
2017-10-28 07:39:35 +02:00
ASSERT_THROW ( checkCode ( " { } < class template < > , { = } ; class... > \n "
2017-11-27 23:32:20 +01:00
" struct Y { } \n "
" class Types { } \n "
" ( X < int > \" uses template \" ) ( < ( ) \" uses ; "
" ( int int ::primary \" uses template \" ) int double \" uses ) "
" ::primary , \" uses template \" ; \n " ) , InternalError ) ;
2015-05-07 20:34:57 +02:00
}
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-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
2022-03-14 17:59:29 +01:00
checkCode ( " int { }; struct A<void> a = { } " ) ;
2015-05-23 23:18:59 +02:00
}
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
2017-12-29 22:47:07 +01:00
ASSERT_THROW ( checkCode ( " struct true template < > { = } > struct Types \" s \" ; static_assert < int > ; " ) , InternalError ) ;
2015-05-24 10:03:50 +02:00
}
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
2017-05-18 17:26:00 +02:00
checkCode ( " { d \" ) d ... \" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \" \" } } " ) ;
2015-05-28 21:12:02 +02:00
}
2015-05-28 21:38:20 +02:00
void garbageCode49 ( ) { // #6715
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) } " ) , InternalError ) ;
2015-05-28 21:38:20 +02:00
}
2015-05-29 19:15:41 +02:00
void garbageCode51 ( ) { // #6719
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( 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 = } " ) , InternalError ) ;
2015-05-29 18:34:00 +02:00
}
2015-05-29 20:20:05 +02:00
void garbageCode53 ( ) { // #6721
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " { { } }; void foo (struct int i) { x->b[i] = = } " ) , InternalError ) ;
2015-05-29 19:30:55 +02:00
}
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
2021-05-01 11:39:26 +02:00
ASSERT_THROW ( checkCode ( " () __attribute__((constructor)); { } { } " ) , InternalError ) ;
2015-05-30 19:15:53 +02:00
}
2015-05-30 20:55:36 +02:00
void garbageCode56 ( ) { // #6713
2015-10-12 18:14:56 +02:00
ASSERT_THROW ( checkCode ( " void foo() { int a = 0; int b = ???; } " ) , InternalError ) ;
2015-05-30 20:55:36 +02:00
}
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
2019-04-19 17:42:21 +02:00
ASSERT_THROW ( checkCode ( " { }> {= ~A()^{} }P { } " ) , InternalError ) ;
2018-09-08 21:10:34 +02:00
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: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
2023-03-26 17:16:33 +02:00
// TODO write some syntax error
checkCode ( " { } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref " ) ;
2015-06-02 20:09:12 +02:00
}
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 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
2017-01-06 11:53:17 +01:00
ASSERT_THROW ( checkCode ( " _lenraw(const char* digits) { } typedef decltype(sizeof(0)) { } operator " ) , InternalError ) ;
2015-06-03 11:39:30 +02:00
}
2015-06-03 17:17:53 +02:00
void garbageCode76 ( ) { // #6754
2016-07-22 16:54:24 +02:00
ASSERT_THROW ( checkCode ( " ( ) ( ) { ( ) [ ] } TEST ( ) { ( _broadcast_f32x4 ) ( ) ( ) ( ) ( ) if ( ) ( ) ; } E mask = ( ) [ ] ( ) res1.x = " ) , InternalError ) ;
2015-06-03 17:17:53 +02:00
}
2015-06-05 14:34:53 +02:00
void garbageCode77 ( ) { // #6755
2017-10-28 07:39:35 +02:00
ASSERT_THROW ( checkCode ( " void foo (int **p) { { { };>= } } unsigned *d = (b b--) --*d " ) , InternalError ) ;
2015-06-04 17:45:12 +02:00
}
2015-06-05 14:34:53 +02:00
void garbageCode78 ( ) { // #6756
2017-01-06 11:53:17 +01:00
ASSERT_THROW ( checkCode ( " ( ) { [ ] } ( ) { } const_array_of_int ( ) { } typedef int A [ ] [ ] ; A a = { { } { } } " ) , InternalError ) ;
2015-06-04 17:45:12 +02:00
}
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
2021-08-04 22:30:39 +02:00
ASSERT_THROW ( checkCode ( " namespace A { class } class A { friend C ; } { } ; " ) , InternalError ) ;
2015-06-14 22:18:28 +02:00
}
2015-06-22 11:12:46 +02:00
void garbageCode84 ( ) { // #6780
2015-09-23 10:33:55 +02:00
ASSERT_THROW ( checkCode ( " int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { } " ) , InternalError ) ; // do not crash
2015-06-22 11:12:46 +02:00
}
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
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " ((X (128))) (int a) { v[ = {} (x 42) a] += } " ) , InternalError ) ; // do not crash
2015-06-24 16:54:23 +02:00
}
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-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
2018-10-22 00:28:09 +02:00
ASSERT_THROW ( checkCode ( " typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] } " ) , InternalError ) ; // throw syntax error
2015-06-25 08:57:09 +02:00
}
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-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
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " { } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } } " ) , InternalError ) ; // do not crash
2015-06-30 19:40:22 +02:00
}
2015-07-01 16:31:49 +02:00
void garbageCode96 ( ) { // #6807
2018-10-22 00:28:09 +02:00
ASSERT_THROW ( checkCode ( " typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ; " ) , InternalError ) ; // throw syntax error
2015-07-01 16:31:49 +02:00
}
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 "
2019-01-06 17:15:57 +01:00
" const unsigned in; \n "
2015-07-14 21:07:10 +02:00
" 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 "
2021-02-20 12:58:42 +01:00
" i, :: a :: b integer, } foo2(x) :: j(:) \n "
2015-07-15 15:18:22 +02:00
" b type(*), d(:), a x :: end d(..), foo end \n "
" foo4 b d(..), a a x type(*), b foo2 b " ) , InternalError ) ;
}
void garbageCode100 ( ) { // #6840
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " ( ) { ( i< ) } int foo ( ) { int i ; ( for ( i => 1 ) ; ) } " ) , InternalError ) ;
2015-07-15 15:18:22 +02:00
}
2015-07-17 21:30:34 +02:00
void garbageCode101 ( ) { // #6835
// Reported case
2019-07-03 08:28:24 +02:00
ASSERT_THROW ( checkCode ( " template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 } " ) , InternalError ) ;
2015-07-17 21:30:34 +02:00
// Reduced case
2019-07-03 08:28:24 +02:00
ASSERT_THROW ( checkCode ( " template < class =( , ) X = 1> struct A {}; A<void> a; " ) , InternalError ) ;
2015-07-17 21:30:34 +02:00
}
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
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " template < Types > struct S {> ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } { ( )> >} { ( ) { } } ( ) { ( ) } " ) , InternalError ) ;
2015-07-21 13:40:50 +02:00
}
2015-07-22 13:32:34 +02:00
void garbageCode105 ( ) { // #6859
2017-10-28 07:39:35 +02:00
ASSERT_THROW ( checkCode ( " void foo (int i) { int a , for (a 1; a( < 4; a++) if (a) (b b++) (b);) n++; } " ) , InternalError ) ;
2015-07-22 13:32:34 +02:00
}
2015-07-28 18:41:50 +02:00
void garbageCode106 ( ) { // #6880
ASSERT_THROW ( checkCode ( " [ ] typedef typedef b_array b_array_ref [ ; ] ( ) b_array_ref b_array_ref_gbl_obj0 { ; { b_array_ref b_array_ref_gbl_obj0 } } " ) , InternalError ) ;
}
void garbageCode107 ( ) { // #6881
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { val = 1{ }; { const} }; { } Bar { const int A = val const } ; " ) , InternalError ) ;
2015-07-28 18:41:50 +02:00
}
2015-07-30 17:19:19 +02:00
void garbageCode108 ( ) { // #6895 "segmentation fault (invalid code) in CheckCondition::isOppositeCond"
2017-08-15 23:18:46 +02:00
ASSERT_THROW ( checkCode ( " A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } } " ) , InternalError ) ;
2015-07-30 17:19:19 +02:00
}
2015-07-31 20:24:06 +02:00
void garbageCode109 ( ) { // #6900 "segmentation fault (invalid code) in CheckStl::runSimplifiedChecks"
checkCode ( " ( *const<> (( ) ) { } ( *const ( ) ( ) ) { } ( * const<> ( size_t )) ) { } ( * const ( ) ( ) ) { } " ) ;
}
void garbageCode110 ( ) { // #6902 "segmentation fault (invalid code) in CheckStl::string_c_str"
2017-10-28 07:39:35 +02:00
ASSERT_THROW ( checkCode ( " ( *const<> ( size_t ) ; foo ) { } * ( *const ( size_t ) ( ) ;> foo )< { } " ) , InternalError ) ;
2015-07-31 20:24:06 +02:00
}
2015-08-01 07:39:56 +02:00
void garbageCode111 ( ) { // #6907
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { FOO = 1( ,) } {{ FOO }} ; " ) , InternalError ) ;
2015-08-01 07:39:56 +02:00
}
2015-08-01 12:31:16 +02:00
void garbageCode112 ( ) { // #6909
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { FOO = ( , ) } {{ }}>> enum { FOO< = ( ) } { { } } ; " ) , InternalError ) ;
2015-08-01 12:24:22 +02:00
}
2015-08-16 14:48:56 +02:00
void garbageCode114 ( ) { // #2118
2019-08-27 06:37:58 +02:00
checkCode ( " Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, { \n "
" for (unsigned i = 0 ; i < count; i++) { \n "
" } \n "
" }); " ) ;
2015-08-16 14:48:56 +02:00
}
void garbageCode115 ( ) { // #5506
2017-12-29 22:47:07 +01:00
ASSERT_THROW ( checkCode ( " A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ; " ) , InternalError ) ;
2015-08-16 14:48:56 +02:00
}
void garbageCode116 ( ) { // #5356
2017-10-28 07:39:35 +02:00
ASSERT_THROW ( checkCode ( " struct template<int { = }; > struct B { }; B < 0 > b; " ) , InternalError ) ;
2015-08-16 14:48:56 +02:00
}
void garbageCode117 ( ) { // #6121
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum E { f = {} }; \n "
" int a = f; " ) , InternalError ) ;
2015-08-16 14:48:56 +02:00
}
void garbageCode118 ( ) { // #5600 - missing include causes invalid enum
ASSERT_THROW ( checkCode ( " enum { \n "
2021-02-20 12:58:42 +01:00
" NUM_OPCODES = \n "
2015-08-16 14:48:56 +02:00
// #include "definition"
" }; \n "
" struct bytecode {}; \n "
" jv jq_next() { opcode = ((opcode) +NUM_OPCODES); \n "
" } " ) , InternalError ) ;
}
2015-08-16 19:11:56 +02:00
void garbageCode119 ( ) { // #5598
2015-10-19 20:03:33 +02:00
checkCode ( " { { void foo() { struct }; template <typename> struct S { Used x; void bar() } auto f = [this] { }; } }; " ) ;
2015-08-16 19:11:56 +02:00
}
void garbageCode120 ( ) { // #4927
checkCode ( " int main() { \n "
" return 0 \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
void garbageCode121 ( ) { // #2585
2021-08-07 20:51:18 +02:00
ASSERT_THROW ( checkCode ( " abcdef? " " ?< "
" 123456? " " ?> "
" +? " " ?= " ) , InternalError ) ;
2015-08-16 19:11:56 +02:00
}
void garbageCode122 ( ) { // #6303
checkCode ( " void foo() { \n "
" char *a = malloc(10); \n "
" a[0] \n "
" } " ) ;
}
void garbageCode123 ( ) {
2020-05-20 18:52:46 +02:00
checkCode ( " namespace pr16989 { \n "
" class C { \n "
" C tpl_mem(T *) { return } \n "
" }; \n "
" } " ) ;
2015-08-16 19:11:56 +02:00
}
2015-09-05 08:38:50 +02:00
void garbageCode125 ( ) {
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " { T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) } " ) , InternalError ) ;
2015-09-05 08:38:50 +02:00
ASSERT_THROW ( checkCode ( " template < Types > struct S :{ ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } " ) ,
InternalError ) ;
}
2015-09-23 10:33:55 +02:00
void garbageCode126 ( ) {
ASSERT_THROW ( checkCode ( " { } float __ieee754_sinhf ( float x ) { float t , , do { gf_u ( jx ) { } ( 0 ) return ; ( ) { } t } ( 0x42b17180 ) { } } " ) ,
InternalError ) ;
}
2015-09-30 21:55:32 +02:00
void garbageCode127 ( ) { // #6667
checkCode ( " extern \" C \" int printf(const char* fmt, ...); \n "
" class A { \n "
" public: \n "
" int Var; \n "
" A(int arg) { Var = arg; } \n "
" ~A() { printf( \" A d'tor \\ n \" ); } \n "
" }; \n "
" const A& foo(const A& arg) { return arg; } \n "
2021-02-20 12:58:42 +01:00
" foo(A(12)).Var " ) ;
2015-09-30 21:55:32 +02:00
}
2015-10-02 15:33:23 +02:00
void garbageCode128 ( ) {
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { FOO = ( , ) } {{ }} enum {{ FOO << = } ( ) } {{ }} ; " ) ,
InternalError ) ;
2015-10-03 10:47:23 +02:00
}
void garbageCode129 ( ) {
ASSERT_THROW ( checkCode ( " operator - ( { } typedef typename x ; ( ) ) { ( { { ( ( ) ) } ( { } ) } ) } " ) ,
InternalError ) ;
}
void garbageCode130 ( ) {
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { FOO = ( , ){ } { { } } { { FOO} = } ( ) } { { } } enumL \" ( enumL \" { { FOO } ( ) } { { } } ; " ) ,
InternalError ) ;
2015-10-02 15:33:23 +02:00
}
2015-10-06 11:21:31 +02:00
void garbageCode131 ( ) {
2018-10-28 17:17:53 +01:00
ASSERT_THROW ( checkCode ( " ( void ) { ( ) } ( ) / { ( ) } " ) , InternalError ) ;
2015-10-06 11:21:31 +02:00
// actually the invalid code should trigger an syntax error...
}
2015-10-07 13:52:06 +02:00
void garbageCode132 ( ) { // #7022
2019-11-14 21:18:31 +01:00
ASSERT_THROW ( checkCode ( " () () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () } " ) , InternalError ) ;
2015-10-07 13:52:06 +02:00
}
2015-10-07 22:45:38 +02:00
void garbageCode133 ( ) {
ASSERT_THROW ( checkCode ( " void f() {{} " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f()) {} " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() \n "
" { \n "
" foo(; \n "
" } \n " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() \n "
" { \n "
" for(;;){ foo(); \n "
" } \n " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() \n "
" { \n "
" a[10; \n "
" } \n " ) , InternalError ) ;
{
const char code [ ] = " { \n "
2019-01-05 11:56:21 +01:00
" a( \n " // <- error
2015-10-07 22:45:38 +02:00
" } \n "
" { \n "
" b()); \n "
" } \n " ;
2019-01-05 11:56:21 +01:00
ASSERT_EQUALS ( " [test.cpp:2] Unmatched '('. Configuration: ''. " , getSyntaxError ( code ) ) ;
}
{
const char code [ ] = " void f() { \n "
" int x = 3) + 0; \n " // <- error: unmatched )
" } \n " ;
ASSERT_EQUALS ( " [test.cpp:2] Unmatched ')'. Configuration: ''. " , getSyntaxError ( code ) ) ;
}
{
const char code [ ] = " void f() { \n "
" int x = (3] + 0; \n " // <- error: unmatched ]
" } \n " ;
ASSERT_EQUALS ( " [test.cpp:2] Unmatched ']'. Configuration: ''. " , getSyntaxError ( code ) ) ;
}
{
const char code [ ] = " void f() { \n " // <- error: unmatched {
" { \n "
" } \n " ;
ASSERT_EQUALS ( " [test.cpp:1] Unmatched '{'. Configuration: ''. " , getSyntaxError ( code ) ) ;
2015-10-07 22:45:38 +02:00
}
}
void garbageCode134 ( ) {
// Ticket #5605, #5759, #5762, #5774, #5823, #6059
2017-01-06 11:53:17 +01:00
ASSERT_THROW ( checkCode ( " foo() template<typename T1 = T2 = typename = unused, T5 = = unused> struct tuple Args> tuple<Args...> { } main() { foo<int,int,int,int,int,int>(); } " ) , InternalError ) ;
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " ( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; } " ) , InternalError ) ;
2018-10-13 18:38:44 +02:00
ASSERT_THROW ( checkCode ( " () template < T = typename = x > struct a {} { f <int> () } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " template < T = typename = > struct a { f <int> } " ) , InternalError ) ;
2017-12-31 16:25:41 +01:00
checkCode ( " struct S { int i, j; }; "
" template<int S::*p, typename U> struct X {}; "
" X<&S::i, int> x = X<&S::i, int>(); "
2021-02-20 12:58:42 +01:00
" X<&S::j, int> y = X<&S::j, int>(); " ) ;
2015-10-07 22:45:38 +02:00
checkCode ( " template <typename T> struct A {}; "
" template <> struct A<void> {}; "
" void foo(const void* f = 0) {} " ) ;
checkCode ( " template<typename... T> struct A { "
" static const int s = 0; "
" }; "
" A<int> a; " ) ;
checkCode ( " template<class T, class U> class A {}; "
" template<class T = A<int, int> > class B {}; "
" template<class T = B<int> > class C { "
" C() : _a(0), _b(0) {} "
" int _a, _b; "
" }; " ) ;
checkCode ( " template<class... T> struct A { "
" static int i; "
" }; "
" void f() { A<int>::i = 0; } " ) ;
}
2015-10-08 11:35:51 +02:00
void garbageCode135 ( ) { // #4994
checkCode ( " long f () { \n "
" return a >> extern \n "
" } \n "
" long a = 1 ; \n "
" long b = 2 ; " ) ;
}
2015-10-09 13:06:52 +02:00
void garbageCode136 ( ) { // #7033
2017-05-01 14:10:06 +02:00
ASSERT_THROW ( checkCode ( " { } () { void f() { node_t * n; for (; -n) {} } } { } " ) ,
InternalError ) ;
2015-10-09 13:06:52 +02:00
}
2015-10-09 13:49:17 +02:00
void garbageCode137 ( ) { // #7034
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " \" \" typedef signed char f; \" \" ; void a() { f * s = () &[]; (; ) (; ) } " ) , InternalError ) ;
2015-10-09 13:49:17 +02:00
}
2015-10-12 18:14:56 +02:00
void garbageCode138 ( ) { // #6660
checkCode ( " CS_PLUGIN_NAMESPACE_BEGIN(csparser) \n "
" { \n "
" struct foo \n "
" { \n "
" union \n "
" {}; \n "
" } halo; \n "
" } \n "
" CS_PLUGIN_NAMESPACE_END(csparser) " ) ;
}
void garbageCode139 ( ) { // #6659 heap user after free: kernel: sm750_accel.c
ASSERT_THROW ( checkCode ( " void hw_copyarea() { \n "
" de_ctrl = (nDirection == RIGHT_TO_LEFT) ? \n "
" ( (0 & ~(((1 << (1 - (0 ? DE_CONTROL_DIRECTION))) - 1) << (0 ? DE_CONTROL_DIRECTION))) ) \n "
" : 42; \n "
" } " ) , InternalError ) ;
}
void garbageCode140 ( ) { // #7035
ASSERT_THROW ( checkCode ( " int foo(int align) { int off(= 0 % align; return off) ? \\ align - off : 0; \\ } " ) , InternalError ) ;
}
2015-10-14 20:34:55 +02:00
void garbageCode141 ( ) { // #7043
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { X = << { X } } enum { X = X } = X ; " ) , InternalError ) ;
2015-10-14 20:34:55 +02:00
}
2015-10-15 21:27:55 +02:00
void garbageCode142 ( ) { // #7050
checkCode ( " { } ( ) { void mapGraphs ( ) { node_t * n ; for (!oid n ) { } } } { } " ) ;
}
2015-10-18 11:52:25 +02:00
void garbageCode143 ( ) { // #6922
ASSERT_THROW ( checkCode ( " void neoProgramShadowRegs() { \n "
" int i; \n "
" Bool noProgramShadowRegs; \n "
" if (noProgramShadowRegs) { \n "
" } else { \n "
" switch (nPtr->NeoPanelWidth) { \n "
" case 1280: \n "
" VGAwCR(0x64,0x?? ); \n "
" } \n "
" } \n "
" } " ) , InternalError ) ;
}
2015-10-06 11:21:31 +02:00
2015-10-18 15:47:37 +02:00
void garbageCode144 ( ) { // #6865
2017-10-28 07:39:35 +02:00
ASSERT_THROW ( checkCode ( " template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ; " ) , InternalError ) ;
2015-10-18 15:47:37 +02:00
}
2015-10-31 18:10:42 +01:00
void garbageCode146 ( ) { // #7081
ASSERT_THROW ( checkCode ( " void foo() { \n "
" ? std::cout << pow((, 1) << std::endl; \n "
" double <ip = NUO ip) << std::end; \n "
" } " ) , InternalError ) ;
}
2015-11-02 21:30:28 +01:00
void garbageCode147 ( ) { // #7082
2019-04-19 17:42:21 +02:00
ASSERT_THROW ( checkCode ( " free(3(); \n "
" $ vWrongAllocp1) test1<int, -!>() ^ { \n "
" int *p<ynew int[n]; \n "
" delete[]p; \n "
" int *p1 = (int*)malloc(n*sizeof(int)); \n "
" free(p1); \n "
" } \n "
" void est2() { \n "
" for (int ui = 0; ui < 1z; ui++) \n "
" ; \n "
" } " ) , InternalError ) ;
2015-11-02 22:14:41 +01:00
2019-04-19 17:42:21 +02:00
ASSERT_THROW ( checkCode ( " ; void f ^ { return } int main ( ) { } " ) , InternalError ) ; // #4941
2015-11-02 21:30:28 +01:00
}
2015-11-04 10:10:20 +01:00
void garbageCode148 ( ) { // #7090
ASSERT_THROW ( checkCode ( " void f_1() { \n "
" typedef S0 b[][1][1] != 0 \n "
" }; \n "
" b[K][0] S0 b[][1][1] != 4{ 0 }; \n "
" b[0][0] " ) , InternalError ) ;
}
2015-11-04 10:26:55 +01:00
void garbageCode149 ( ) { // #7085
checkCode ( " int main() { \n "
" for (j = 0; j < 1; j) \n "
" j6; \n "
" } " ) ;
}
2015-11-05 19:00:08 +01:00
void garbageCode150 ( ) { // #7089
ASSERT_THROW ( checkCode ( " class A { \n "
" pl vFoo() { \n "
" A:: \n "
" }; \n "
" A:: \n "
" } \n " ) , InternalError ) ;
}
2016-11-20 17:59:50 +01:00
void garbageCode151 ( ) { // #4911 - bad simplification => don't crash
checkCode ( " void f() { \n "
2015-11-06 21:58:49 +01:00
" int a; \n "
" do { a=do_something() } while (a); \n "
" } " ) ;
}
2016-11-27 11:40:42 +01:00
void garbageCode152 ( ) { // happened in travis, originally from llvm clang code
2015-11-07 20:43:58 +01:00
const char * code = " template <bool foo = std::value &&> \n "
" static std::string foo(char *Bla) { \n "
" while (Bla[1] && Bla[1] != ',') } \n " ;
checkCode ( code ) ;
}
2015-11-08 13:45:55 +01:00
void garbageCode153 ( ) {
2016-04-22 06:02:54 +02:00
TODO_ASSERT_THROW ( checkCode ( " enum { X = << { X } } { X X } enum { X = << { ( X ) } } { } X */ " ) , InternalError ) ;
2015-11-08 13:45:55 +01:00
}
2015-11-08 14:21:12 +01:00
void garbageCode154 ( ) {
checkCode ( " \" abc \" []; " ) ;
}
2015-11-09 17:25:20 +01:00
void garbageCode156 ( ) { // #7120
2020-03-07 21:46:38 +01:00
ASSERT_THROW ( checkCode ( " struct {}a; d f() { c ? : } {}a.p " ) , InternalError ) ;
2015-11-09 17:25:20 +01:00
}
2015-11-14 21:22:53 +01:00
void garbageCode157 ( ) { // #7131
ASSERT_THROW ( checkCode ( " namespace std { \n "
" template < typename > \n "
2021-02-20 12:58:42 +01:00
" void swap(); \n "
2015-11-14 21:22:53 +01:00
" } "
" template std::swap \n " ) , InternalError ) ;
}
2015-11-21 20:24:30 +01:00
void garbageCode158 ( ) { // #3238
2021-02-20 12:58:42 +01:00
checkCode ( " __FBSDID( \" ... \" ); " ) ;
2015-11-21 20:24:30 +01:00
}
2015-11-29 14:56:15 +01:00
void garbageCode159 ( ) { // #7119
2019-11-14 21:18:31 +01:00
ASSERT_THROW ( checkCode ( " ({}typedef typename x;typename x!){({{}()})} " ) , InternalError ) ;
2015-12-05 13:55:33 +01:00
}
void garbageCode160 ( ) { // #7190
ASSERT_THROW ( checkCode ( " f(a,b,c,d)float [ a[],d;int ] b[],c;{} " ) , InternalError ) ; // don't hang
2015-11-29 14:56:15 +01:00
}
2015-11-21 20:24:30 +01:00
2018-01-24 13:53:03 +01:00
void garbageCodeFuzzerClientMode1 ( ) {
ASSERT_THROW ( checkCode ( " void f() { x= name2 & name3 name2 = | 0.1 , | 0.1 , | 0.1 name4 <= >( ); } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() { x = , * [ | + 0xff | > 0xff]; } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() { x = , | 0xff , 0.1 < ; } " ) , InternalError ) ;
2018-01-25 15:53:58 +01:00
ASSERT_THROW ( checkCode ( " void f() { x = [ 1 || ] ; } " ) , InternalError ) ;
2018-01-26 09:34:27 +01:00
ASSERT_THROW ( checkCode ( " void f1() { x = name6 1 || ? name3 [ ( 1 || +) ] ; } " ) , InternalError ) ;
2018-01-24 13:53:03 +01:00
}
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 " ;
2018-01-18 08:51:35 +01:00
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
2014-10-16 10:59:46 +02:00
// 6122 survive garbage code
code = " ; { int i ; for ( i = 0 ; = 123 ; ) - ; } " ;
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( code ) , InternalError ) ;
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 ; } ) { } " ) ;
2018-04-02 13:14:48 +02:00
ASSERT_THROW ( checkCode ( " { }; void namespace A::f; { g() { int } } " ) , InternalError ) ;
2014-10-16 10:59:46 +02:00
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 "
2021-02-20 12:58:42 +01:00
" yyterminate(); \n "
2015-02-24 06:11:31 +01:00
" } } " ) ; // #5663
2014-10-16 10:59:46 +02:00
}
2014-11-20 14:20:09 +01:00
void garbageAST ( ) {
2016-07-26 08:50:00 +02:00
ASSERT_THROW ( 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] * {} " ) , InternalError ) ; // Don't hang (#5787)
2014-09-24 13:45:56 +02:00
checkCode ( " START_SECTION([EXTRA](bool isValid(const String &filename))) " ) ; // Don't crash (#5991)
2018-02-10 14:39:57 +01:00
// #8352
ASSERT_THROW ( checkCode ( " else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || "
" { return return { | { - name3 1 enum != >= 1 >= ++ { name6 | ; ++}}}}}}} " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || "
" { return return { | { - name3 1 enum != >= 1 >= ++ { { || ; ++}}}}}}}} " ) , InternalError ) ;
2014-09-24 13:45:56 +02:00
}
2015-01-18 13:13:52 +01:00
void templateSimplifierCrashes ( ) {
2015-08-16 19:11:56 +02:00
checkCode ( // #5950
2021-02-20 12:58:42 +01:00
" struct A { \n "
2015-01-18 13:13:52 +01:00
" template <class T> operator T*(); \n "
2021-02-20 12:58:42 +01:00
" }; \n "
2015-01-18 13:13:52 +01:00
" \n "
" template <> A::operator char*(){ return 0; } // specialization \n "
" \n "
2021-02-20 12:58:42 +01:00
" int main() { \n "
2015-01-18 13:13:52 +01:00
" 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 "
2021-02-20 12:58:42 +01:00
" } " ) ;
2015-01-18 13:13:52 +01:00
2015-08-16 19:11:56 +02:00
checkCode ( // #6034
2015-01-18 13:13:52 +01:00
" 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 "
2021-02-20 12:58:42 +01:00
" } " ) ;
2015-01-18 13:13:52 +01:00
2015-10-19 20:03:33 +02:00
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 "
2021-02-20 12:58:42 +01:00
" SA ((is_last<int, something_like_tuple_t>::value == false)); " ) ;
2015-01-18 13:13:52 +01:00
2015-08-16 19:11:56 +02:00
checkCode ( // #6225
2015-01-18 13:13:52 +01:00
" template <typename...> \n "
" void templ_fun_with_ty_pack() {} \n "
2021-02-20 12:58:42 +01:00
" \n "
2015-01-18 13:13:52 +01:00
" namespace PR20047 { \n "
" template <typename T> \n "
" struct A {}; \n "
" using AliasA = A<T>; \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2015-08-16 19:11:56 +02:00
// #3449
2020-11-23 18:29:08 +01:00
ASSERT_EQUALS ( " template < typename T > struct A ; \n "
2015-08-16 19:11:56 +02:00
" struct B { template < typename T > struct C } ; \n "
" { } ; " ,
checkCode ( " template<typename T> struct A; \n "
" struct B { template<typename T> struct C }; \n "
" {}; " ) ) ;
2015-01-18 13:13:52 +01:00
}
2015-12-09 14:00:40 +01:00
void garbageCode161 ( ) {
//7200
ASSERT_THROW ( checkCode ( " { }{ if () try { } catch (...)} B : : ~B { } " ) , InternalError ) ;
}
2015-12-12 15:39:38 +01:00
void garbageCode162 ( ) {
//7208
2015-12-12 20:01:03 +01:00
ASSERT_THROW ( checkCode ( " return << >> x return << >> x " , false ) , InternalError ) ;
2015-12-12 15:39:38 +01:00
}
2015-12-26 01:37:21 +01:00
2015-12-26 00:21:56 +01:00
void garbageCode163 ( ) {
//7228
ASSERT_THROW ( checkCode ( " typedef s f[](){typedef d h(;f)} " , false ) , InternalError ) ;
}
2015-12-12 15:39:38 +01:00
2015-12-26 23:51:10 +01:00
void garbageCode164 ( ) {
2015-12-26 20:16:01 +01:00
//7234
2020-07-18 06:02:12 +02:00
ASSERT_THROW ( checkCode ( " class d{k p;}(){d::d():B<()} " ) , InternalError ) ;
2015-12-26 20:16:01 +01:00
}
2015-12-26 23:51:10 +01:00
void garbageCode165 ( ) {
2015-12-26 20:26:07 +01:00
//7235
2017-05-01 14:10:06 +02:00
ASSERT_THROW ( checkCode ( " for(;..) " , false ) , InternalError ) ;
2015-12-26 20:26:07 +01:00
}
2015-12-26 23:51:10 +01:00
void garbageCode167 ( ) {
//7237
2017-04-06 08:50:35 +02:00
ASSERT_THROW ( checkCode ( " class D00i000{:D00i000::}i " ) , InternalError ) ;
2015-12-26 23:51:10 +01:00
}
2015-12-31 14:17:52 +01:00
void garbageCode168 ( ) {
// 7246
checkCode ( " long foo(void) { return *bar; } " , false ) ;
}
2016-01-01 23:32:10 +01:00
void garbageCode169 ( ) {
// 6713
ASSERT_THROW ( checkCode ( " ( ) { ( ) ; { return } switch ( ) i \n "
" set case break ; default: ( ) } " , false ) , InternalError ) ;
}
2016-01-03 20:53:03 +01:00
void garbageCode170 ( ) {
// 7255
2019-07-03 08:28:24 +02:00
ASSERT_THROW ( checkCode ( " d i(){{f*s=typeid(()0,)}} " , false ) , InternalError ) ;
2016-01-03 20:53:03 +01:00
}
2016-01-08 15:24:05 +01:00
void garbageCode171 ( ) {
2016-01-08 11:59:02 +01:00
// 7270
ASSERT_THROW ( checkCode ( " (){case()?():}: " , false ) , InternalError ) ;
}
2016-01-03 20:53:03 +01:00
2016-01-26 19:12:57 +01:00
void garbageCode172 ( ) {
// #7357
ASSERT_THROW ( checkCode ( " p<e T=l[<]<>>, " ) , InternalError ) ;
}
2016-01-30 18:20:45 +01:00
void garbageCode173 ( ) {
// #6781 heap corruption ; TemplateSimplifier::simplifyTemplateInstantiations
ASSERT_THROW ( checkCode ( " template < Types > struct S : >( S < ...Types... > S <) > { ( ) { } } ( ) { return S < void > ( ) } " ) , InternalError ) ;
}
2016-01-31 10:25:09 +01:00
void garbageCode174 ( ) { // #7356
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " {r e() { w*const D = (())D = cast< }} " ) , InternalError ) ;
2016-01-31 10:25:09 +01:00
}
2016-01-31 22:16:58 +01:00
void garbageCode175 ( ) { // #7027
ASSERT_THROW ( checkCode ( " int f() { \n "
" int i , j; \n "
" for ( i = t3 , i < t1 ; i++ ) \n "
" for ( j = 0 ; j < = j++ ) \n "
" return t1 , \n "
" } " ) , InternalError ) ;
}
2016-02-03 21:52:02 +01:00
void garbageCode176 ( ) { // #7527
checkCode ( " class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ; " ) ;
}
2016-02-03 22:49:57 +01:00
2016-02-04 09:10:20 +01:00
void garbageCode181 ( ) {
2018-12-01 17:29:41 +01:00
ASSERT_THROW ( checkCode ( " int test() { int +; } " ) , InternalError ) ;
2016-02-04 09:10:20 +01:00
}
2016-05-17 22:19:23 +02:00
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
void garbageCode182 ( ) {
ASSERT_THROW ( checkCode ( " enum { int f ( ) { return = } r = f ( ) ; } " ) , InternalError ) ;
}
2016-05-25 13:14:34 +02:00
// #7505 - segfault
void garbageCode183 ( ) {
ASSERT_THROW ( checkCode ( " = { int } enum return { r = f() f(); } " ) , InternalError ) ;
}
2016-05-17 22:19:23 +02:00
2016-08-21 11:06:48 +02:00
void garbageCode184 ( ) { // #7699
2020-03-07 21:46:38 +01:00
ASSERT_THROW ( checkCode ( " unsigned int AquaSalSystem::GetDisplayScreenCount() { \n "
" NSArray* pScreens = [NSScreen screens]; \n "
" return pScreens ? [pScreens count] : 1; \n "
" } " ) , InternalError ) ;
2016-08-21 11:06:48 +02:00
}
2017-01-08 02:36:21 +01:00
void garbageCode185 ( ) { // #6011 crash in libreoffice failure to create proper AST
checkCode (
" namespace binfilter \n "
" { \n "
" BOOL EnhWMFReader::ReadEnhWMF() \n "
" { \n "
" pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) ); \n "
" return bStatus; \n "
" }; \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2017-01-08 02:36:21 +01:00
}
2017-08-15 22:40:55 +02:00
// #8151 - segfault due to incorrect template syntax
void garbageCode186 ( ) {
ASSERT_THROW ( checkCode ( " A<B<><>C " ) , InternalError ) ;
}
2017-08-15 23:18:46 +02:00
void garbageCode187 ( ) { // # 8152 - segfault in handling
const std : : string inp ( " 0| \0 |0>; \n " , 8 ) ;
ASSERT_THROW ( checkCode ( inp ) , InternalError ) ;
2018-03-22 09:07:58 +01:00
checkCode ( " template<class T> struct S : A< B<T> || C<T> > {}; " ) ; // No syntax error: #8390
2018-03-22 15:20:37 +01:00
checkCode ( " static_assert(A<x> || B<x>, ab); " ) ;
2017-10-28 07:39:35 +02:00
}
void garbageCode188 ( ) { // #8255
ASSERT_THROW ( checkCode ( " {z r(){(){for(;<(x);){if(0==0)}}}} " ) , InternalError ) ;
2017-08-15 23:18:46 +02:00
}
2017-08-15 22:40:55 +02:00
2018-01-07 12:52:28 +01:00
void garbageCode189 ( ) { // #8317
checkCode ( " t&n(){()()[](){()}}$ " ) ;
}
2018-01-07 13:11:56 +01:00
void garbageCode190 ( ) { // #8307
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " void foo() { \n "
" int i; \n "
" i *= 0; \n "
" !i <; \n "
" } " ) ,
InternalError ) ;
2018-01-07 13:11:56 +01:00
}
2018-01-18 08:51:35 +01:00
void garbageCode191 ( ) { // #8333
ASSERT_THROW ( checkCode ( " struct A { int f(const); }; " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " struct A { int f(int, const, char); }; " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " struct A { int f(struct); }; " ) , InternalError ) ;
// The following code is valid and should not trigger any error
checkCode ( " struct A { int f ( char ) ; } ; " ) ;
}
2018-02-03 15:50:05 +01:00
void garbageCode192 ( ) { // #8386 (segmentation fault)
ASSERT_THROW ( checkCode ( " {(()[((0||0xf||))]0[])} " ) , InternalError ) ;
}
2018-09-08 21:10:34 +02:00
// #8740
2018-09-09 07:10:37 +02:00
void garbageCode193 ( ) {
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " d f(){!=[]&&0()!=0} " ) , InternalError ) ;
}
// #8384
2018-09-09 07:10:37 +02:00
void garbageCode194 ( ) {
2018-09-08 21:10:34 +02:00
ASSERT_THROW ( checkCode ( " {((()))(return 1||);} " ) , InternalError ) ;
}
2019-09-12 20:52:39 +02:00
// #8709 - no garbage but to avoid stability regression
2018-09-10 08:40:53 +02:00
void garbageCode195 ( ) {
checkCode ( " a b; \n "
" void c() { \n "
" switch (d) { case b:; } \n "
" double e(b); \n "
" if(e <= 0) {} \n "
" } " ) ;
}
2018-09-10 16:17:44 +02:00
// #8265
void garbageCode196 ( ) {
ASSERT_THROW ( checkCode ( " 0|,0<<V " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " ;|4|<0; " ) , InternalError ) ;
}
2018-09-10 16:24:09 +02:00
// #8385
void garbageCode197 ( ) {
ASSERT_THROW ( checkCode ( " (){e break,{(case)|{e:[()]}}} " ) , InternalError ) ;
}
2018-09-10 16:28:32 +02:00
// #8383
void garbageCode198 ( ) {
ASSERT_THROW ( checkCode ( " void f(){ \n "
" x= ={(continue continue { ( struct continue { ( ++ name5 name5 ) ( name5 name5 n \n "
" ame5 ( name5 struct ( name5 name5 < ) ) ( default ) { name4 != name5 name5 name5 \n "
" ( name5 name5 name5 ( { 1 >= void { ( ()) } 1 name3 return >= >= ( ) >= name5 ( \n "
" name5 name6 :nam00 [ ()])}))})})})}; \n "
" } " ) , InternalError ) ;
}
2018-09-13 09:19:15 +02:00
// #8752
void garbageCode199 ( ) {
2021-08-07 20:51:18 +02:00
checkCode ( " d f(){e n00e0[]n00e0& " " 0+f=0} " ) ;
2018-09-13 09:19:15 +02:00
}
2018-10-28 17:17:53 +01:00
// #8757
void garbageCode200 ( ) {
ASSERT_THROW ( checkCode ( " (){e break,{(case)!{e:[]}}} " ) , InternalError ) ;
}
2018-12-01 17:29:41 +01:00
// #8873
void garbageCode201 ( ) {
ASSERT_THROW ( checkCode ( " void f() { std::string s= \" abc \" ; return s + } " ) , InternalError ) ;
}
2019-01-01 19:30:13 +01:00
// #8907
void garbageCode202 ( ) {
ASSERT_THROW ( checkCode ( " void f() { UNKNOWN_MACRO(return); } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() { UNKNOWN_MACRO(throw); } " ) , InternalError ) ;
}
2019-02-11 07:45:03 +01:00
void garbageCode203 ( ) { // #8972
checkCode ( " { > () {} } " ) ;
checkCode ( " template <> a > ::b(); " ) ;
}
2019-06-03 07:06:04 +02:00
void garbageCode204 ( ) {
2019-07-03 08:28:24 +02:00
ASSERT_THROW ( checkCode ( " template <a, = b<>()> c; template <a> a as() {} as<c<>>(); " ) , InternalError ) ;
2019-06-03 07:06:04 +02:00
}
2019-07-10 07:16:16 +02:00
void garbageCode205 ( ) {
checkCode ( " class CodeSnippetsEvent : public wxCommandEvent { \n "
" public : \n "
" CodeSnippetsEvent ( wxEventType commandType = wxEventType , int id = 0 ) ; \n "
" CodeSnippetsEvent ( const CodeSnippetsEvent & event ) ; \n "
" virtual wxEvent * Clone ( ) const { return new CodeSnippetsEvent ( * this ) ; } \n "
" private : \n "
" int m_SnippetID ; \n "
" } ; \n "
" const wxEventType wxEVT_CODESNIPPETS_GETFILELINKS = wxNewEventType ( ) \n "
" CodeSnippetsEvent :: CodeSnippetsEvent ( wxEventType commandType , int id ) \n "
" : wxCommandEvent ( commandType , id ) { \n "
" } \n "
" CodeSnippetsEvent :: CodeSnippetsEvent ( const CodeSnippetsEvent & Event ) \n "
" : wxCommandEvent ( Event ) \n "
" , m_SnippetID ( 0 ) { \n "
" } " ) ; // don't crash
}
2019-11-09 18:00:21 +01:00
void garbageCode206 ( ) {
2019-11-15 07:03:57 +01:00
ASSERT_EQUALS ( " [test.cpp:1] syntax error: operator " , getSyntaxError ( " void foo() { for (auto operator new : int); } " ) ) ;
ASSERT_EQUALS ( " [test.cpp:1] syntax error: operator " , getSyntaxError ( " void foo() { for (a operator== :) } " ) ) ;
2019-11-09 18:00:21 +01:00
}
2019-11-19 21:50:53 +01:00
void garbageCode207 ( ) { // #8750
ASSERT_THROW ( checkCode ( " d f(){(.n00e0(return%n00e0''('')));} " ) , InternalError ) ;
}
void garbageCode208 ( ) { // #8753
ASSERT_THROW ( checkCode ( " d f(){(for(((((0{t b;((((((((()))))))))}))))))} " ) , InternalError ) ;
}
void garbageCode209 ( ) { // #8756
ASSERT_THROW ( checkCode ( " {(- -##0xf/-1 0)[]} " ) , InternalError ) ;
}
void garbageCode210 ( ) { // #8762
ASSERT_THROW ( checkCode ( " {typedef typedef c n00e0[]c000(;n00e0&c000)} " ) , InternalError ) ;
}
void garbageCode211 ( ) { // #8764
ASSERT_THROW ( checkCode ( " {typedef f typedef[]({typedef e e,>;typedef(((typedef<typedef|)))})} " ) , InternalError ) ;
}
void garbageCode212 ( ) { // #8765
ASSERT_THROW ( checkCode ( " {(){}[]typedef r n00e0[](((n00e0 0((;()))))){(0 typedef n00e0 bre00 n00e0())}[]();typedef n n00e0()[],(bre00)} " ) , InternalError ) ;
}
2020-01-01 15:46:09 +01:00
void garbageCode213 ( ) { // #8758
ASSERT_THROW ( checkCode ( " { \" \" [(1||)];} " ) , InternalError ) ;
}
2020-04-09 17:42:51 +02:00
void garbageCode214 ( ) {
checkCode ( " THIS FILE CONTAINS VARIOUS TEXT " ) ;
}
2020-11-28 14:41:05 +01:00
void garbageCode215 ( ) { // daca@home script with extension .c
ASSERT_THROW ( checkCode ( " a = [1,2,3]; " ) , InternalError ) ;
}
2021-10-08 23:14:16 +02:00
void garbageCode216 ( ) { // #7884
checkCode ( " template<typename> struct A {}; \n "
" template<typename...T> struct A<T::T...> {}; \n "
" A<int> a; " ) ;
}
2021-11-16 16:01:10 +01:00
void garbageCode217 ( ) { // #10011
ASSERT_THROW ( checkCode ( " void f() { \n "
" auto p; \n "
" if (g(p)) {} \n "
" assert(); \n "
" } " ) , InternalError ) ;
}
2021-12-20 13:12:19 +01:00
void garbageCode218 ( ) { // #8763
checkCode ( " d f(){t n0000 const[]n0000+0!=n0000,(0)} " ) ; // don't crash
}
void garbageCode219 ( ) { // #10101
checkCode ( " typedef void (*func) (addr) ; \n "
" void bar(void) { \n "
" func f; \n "
" f & = (func)42; \n "
" } \n " ) ; // don't crash
}
2022-02-10 14:13:50 +01:00
void garbageCode220 ( ) { // #6832
ASSERT_THROW ( checkCode ( " (){(){{()}}return;{switch()0 case(){}break;l:()}} \n " ) , InternalError ) ; // don't crash
}
2022-02-15 20:19:03 +01:00
void garbageCode221 ( ) {
ASSERT_THROW ( checkCode ( " struct A<0<; \n " ) , InternalError ) ; // don't crash
}
2022-02-18 12:59:21 +01:00
void garbageCode222 ( ) { // #10763
ASSERT_THROW ( checkCode ( " template<template<class> \n " ) , InternalError ) ; // don't crash
}
2023-03-28 11:24:52 +02:00
void garbageCode223 ( ) { // #11639
ASSERT_THROW ( checkCode ( " struct{}* " ) , InternalError ) ; // don't crash
}
2021-12-20 13:12:19 +01:00
2016-11-20 17:59:50 +01:00
void syntaxErrorFirstToken ( ) {
ASSERT_THROW ( checkCode ( " &operator(){[]}; " ) , InternalError ) ; // #7818
ASSERT_THROW ( checkCode ( " *(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { } " ) , InternalError ) ; // #6858
ASSERT_THROW ( checkCode ( " >{ x while (y) z int = } " ) , InternalError ) ; // #4175
ASSERT_THROW ( checkCode ( " &p(!{}e x){({(0?:?){({})}()})} " ) , InternalError ) ; // #7118
ASSERT_THROW ( checkCode ( " <class T> { struct { typename D4:typename Base<T*> }; }; " ) , InternalError ) ; // #3533
ASSERT_THROW ( checkCode ( " > template < . > struct Y < T > { = } ; \n " ) , InternalError ) ; // #6108
}
void syntaxErrorLastToken ( ) {
2016-11-20 14:15:51 +01:00
ASSERT_THROW ( checkCode ( " int * " ) , InternalError ) ; // #7821
ASSERT_THROW ( checkCode ( " x[y] " ) , InternalError ) ; // #2986
ASSERT_THROW ( checkCode ( " ( ) & " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " || #if #define <= " ) , InternalError ) ; // #2601
ASSERT_THROW ( checkCode ( " f::y:y : <x:: " ) , InternalError ) ; // #6613
ASSERT_THROW ( checkCode ( " a \" b \" not_eq \" c \" " ) , InternalError ) ; // #6720
ASSERT_THROW ( checkCode ( " (int arg2) { } { } typedef void (func_type) (int, int); typedef func_type& " ) , InternalError ) ; // #6738
ASSERT_THROW ( checkCode ( " &g[0]; { (g[0] 0) } = " , false ) , InternalError ) ; // #6744
ASSERT_THROW ( checkCode ( " { { void foo() { struct }; { }; } }; struct S { } f = " , false ) , InternalError ) ; // #6753
ASSERT_THROW ( checkCode ( " { { ( ) } P ( ) ^ { } { } { } ( ) } 0 " ) , InternalError ) ; // #6772
ASSERT_THROW ( checkCode ( " +---+ " ) , InternalError ) ; // #6948
ASSERT_THROW ( checkCode ( " template<> \n " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " ++4++ + + E++++++++++ + ch " " tp.oed5[.] " ) , InternalError ) ; // #7074
ASSERT_THROW ( checkCode ( " d a(){f s=0()8[]s?():0}*()?:0 " , false ) , InternalError ) ; // #7236
ASSERT_THROW ( checkCode ( " !2 : #h2 ?: " , false ) , InternalError ) ; // #7769
ASSERT_THROW ( checkCode ( " -- " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " volatile true , test < test < #ifdef __ppc__ true , " ) , InternalError ) ; // #4169
ASSERT_THROW ( checkCode ( " a,b-- \n " ) , InternalError ) ; // #2847
ASSERT_THROW ( checkCode ( " x a[0] = " ) , InternalError ) ; // #2682
ASSERT_THROW ( checkCode ( " auto_ptr<x> \n " ) , InternalError ) ; // #2967
ASSERT_THROW ( checkCode ( " char a[1] \n " ) , InternalError ) ; // #2865
ASSERT_THROW ( checkCode ( " <><< " ) , InternalError ) ; // #2612
ASSERT_THROW ( checkCode ( " z<y<x> " ) , InternalError ) ; // #2831
ASSERT_THROW ( checkCode ( " ><,f<i, " ) , InternalError ) ; // #2835
ASSERT_THROW ( checkCode ( " 0; (a) < (a) " ) , InternalError ) ; // #2875
ASSERT_THROW ( checkCode ( " ( * const ( size_t ) ; foo ) " ) , InternalError ) ; // #6135
ASSERT_THROW ( checkCode ( " ({ (); strcat(strcat(() ()) ()) }) " ) , InternalError ) ; // #6686
ASSERT_THROW ( checkCode ( " %: return ; () " ) , InternalError ) ; // #3441
2016-11-21 13:54:59 +01:00
ASSERT_THROW ( checkCode ( " __attribute__((destructor)) void " ) , InternalError ) ; // #7816
ASSERT_THROW ( checkCode ( " 1 *p = const " ) , InternalError ) ; // #3512
ASSERT_THROW ( checkCode ( " sizeof " ) , InternalError ) ; // #2599
ASSERT_THROW ( checkCode ( " enum struct " ) , InternalError ) ; // #6718
ASSERT_THROW ( checkCode ( " {(){(())}}r&const " ) , InternalError ) ; // #7321
ASSERT_THROW ( checkCode ( " int " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " struct A : \n " ) , InternalError ) ; // #2591
ASSERT_THROW ( checkCode ( " {} const const \n " ) , InternalError ) ; // #2637
2019-03-26 20:51:41 +01:00
ASSERT_THROW ( checkCode ( " re2c: error: line 14, column 4: can only difference char sets " ) , InternalError ) ;
2016-11-20 14:15:51 +01:00
// ASSERT_THROW( , InternalError)
2016-11-06 14:20:58 +01:00
}
2017-05-25 09:50:14 +02:00
2017-09-15 22:37:31 +02:00
void syntaxErrorCase ( ) {
// case must be inside switch block
2017-09-16 02:13:48 +02:00
ASSERT_THROW ( checkCode ( " void f() { switch (a) {}; case 1: } " ) , InternalError ) ; // #8184
ASSERT_THROW ( checkCode ( " struct V : { public case {} ; struct U : U void { V *f (int x) (x) } } " ) , InternalError ) ; // #5120
2018-10-28 17:17:53 +01:00
ASSERT_THROW ( checkCode ( " void f() { 0 0; } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() { true 0; } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() { 'a' 0; } " ) , InternalError ) ;
ASSERT_THROW ( checkCode ( " void f() { 1 \" \" ; } " ) , InternalError ) ;
2017-09-15 22:37:31 +02:00
}
2019-03-23 18:27:41 +01:00
void syntaxErrorFuzzerCliType1 ( ) {
ASSERT_THROW ( checkCode ( " void f(){x=0,return return''[]()} " ) , InternalError ) ;
2019-03-25 15:29:23 +01:00
ASSERT_THROW ( checkCode ( " void f(){x='0'++'0'(return)[];} " ) , InternalError ) ; // #9063
2019-03-31 10:46:59 +02:00
checkCode ( " void f(){*(int *)42=0;} " ) ; // no syntax error
2019-03-26 16:14:21 +01:00
ASSERT_THROW ( checkCode ( " void f() { x= 'x' > typedef name5 | ( , ;){ } (); } " ) , InternalError ) ; // #9067
2019-03-26 19:57:32 +01:00
ASSERT_THROW ( checkCode ( " void f() { x= {}( ) ( 'x')[ ] (); } " ) , InternalError ) ; // #9068
2019-03-27 18:17:02 +01:00
ASSERT_THROW ( checkCode ( " void f() { x= y{ } name5 y[ ] + y ^ name5 ^ name5 for ( ( y y y && y y y && name5 ++ int )); } " ) , InternalError ) ; // #9069
2019-03-23 18:27:41 +01:00
}
2019-04-19 13:55:25 +02:00
void cliCode ( ) {
// #8913
2021-08-14 22:50:58 +02:00
ASSERT_NO_THROW ( checkCode (
" public ref class LibCecSharp : public CecCallbackMethods { \n "
" array<CecAdapter ^> ^ FindAdapters(String ^ path) {} \n "
" bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) { \n "
" bool bReturn(false); \n "
" } \n "
" }; " ) ) ;
2019-04-19 13:55:25 +02:00
}
2017-05-25 09:50:14 +02:00
void enumTrailingComma ( ) {
ASSERT_THROW ( checkCode ( " enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ; " ) , InternalError ) ; // #8079
}
2018-03-24 07:28:02 +01:00
void nonGarbageCode1 ( ) {
checkCode ( " template <class T> class List { \n "
" public: \n "
" List(); \n "
" virtual ~List(); \n "
" template< class Predicate > u_int DeleteIf( const Predicate &pred ); \n "
" }; \n "
" template< class T > \n "
" template< class Predicate > int \n "
" List<T>::DeleteIf( const Predicate &pred ) \n "
2021-02-20 12:58:42 +01:00
" {} " ) ;
2018-10-13 18:38:44 +02:00
// #8749
checkCode (
2018-10-13 18:42:09 +02:00
" struct A { \n "
" void operator+=(A&) && = delete; \n "
2021-02-20 12:58:42 +01:00
" }; " ) ;
2018-10-13 18:38:44 +02:00
// #8788
checkCode (
2018-10-13 18:42:09 +02:00
" struct foo; \n "
" void f() { \n "
" auto fn = []() -> foo* { return new foo(); }; \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2018-03-24 07:28:02 +01:00
}
2014-09-24 13:45:56 +02:00
} ;
REGISTER_TEST ( TestGarbage )