FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppcheck/test/testvarid.cpp at master · napcode/cppcheck · GitHub
napcode
/
cppcheck
Public
forked from
cppcheck-opensource/cppcheck
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppcheck
/
test
/
testvarid.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
3100 lines (2734 loc) · 127 KB
Breadcrumbs
cppcheck
/
test
/
testvarid.cpp
Copy path
File metadata and controls
3100 lines (2734 loc) · 127 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2019 Cppcheck team.
*
* 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
"
platform.h
"
#
include
"
settings.h
"
#
include
"
standards.h
"
#
include
"
testsuite.h
"
#
include
"
token.h
"
#
include
"
tokenize.h
"
#
include
<
string
>
struct
InternalError
;
class
TestVarID
:
public
TestFixture
{
public:
TestVarID
() : TestFixture(
"
TestVarID
"
) {
}
private:
void
run
() OVERRIDE {
TEST_CASE
(varid1);
TEST_CASE
(varid2);
TEST_CASE
(varid3);
TEST_CASE
(varid4);
TEST_CASE
(varid5);
TEST_CASE
(varid6);
TEST_CASE
(varid7);
TEST_CASE
(varidReturn1);
TEST_CASE
(varidReturn2);
TEST_CASE
(varid8);
TEST_CASE
(varid9);
TEST_CASE
(varid10);
TEST_CASE
(varid11);
TEST_CASE
(varid12);
TEST_CASE
(varid13);
TEST_CASE
(varid14);
TEST_CASE
(varid15);
TEST_CASE
(varid16);
TEST_CASE
(varid17);
//
ticket #1810
TEST_CASE
(varid18);
TEST_CASE
(varid19);
TEST_CASE
(varid20);
TEST_CASE
(varid24);
TEST_CASE
(varid25);
TEST_CASE
(varid26);
//
ticket #1967 (list of function pointers)
TEST_CASE
(varid27);
//
Ticket #2280 (same name for namespace and variable)
TEST_CASE
(varid28);
//
ticket #2630
TEST_CASE
(varid29);
//
ticket #1974
TEST_CASE
(varid30);
//
ticket #2614
TEST_CASE
(varid34);
//
ticket #2825
TEST_CASE
(varid35);
//
function declaration inside function body
TEST_CASE
(varid36);
//
ticket #2980 (segmentation fault)
TEST_CASE
(varid37);
//
ticket #3092 (varid for 'Bar bar(*this);')
TEST_CASE
(varid38);
//
ticket #3272 (varid for 'FOO class C;')
TEST_CASE
(varid39);
//
ticket #3279 (varid for 'FOO::BAR const')
TEST_CASE
(varid40);
//
ticket #3279
TEST_CASE
(varid41);
//
ticket #3340 (varid for union type)
TEST_CASE
(varid42);
//
ticket #3316 (varid for array)
TEST_CASE
(varid43);
TEST_CASE
(varid44);
TEST_CASE
(varid45);
//
#3466
TEST_CASE
(varid46);
//
struct varname
TEST_CASE
(varid47);
//
function parameters
TEST_CASE
(varid48);
//
#3785 - return (a*b)
TEST_CASE
(varid49);
//
#3799 - void f(std::vector<int>)
TEST_CASE
(varid50);
//
#3760 - explicit
TEST_CASE
(varid51);
//
don't set varid for template function
TEST_CASE
(varid52);
//
Set varid for nested templates
TEST_CASE
(varid53);
//
#4172 - Template instantiation: T<&functionName> list[4];
TEST_CASE
(varid54);
//
hang
TEST_CASE
(varid55);
//
#5868: Function::addArgument with varid 0 for argument named the same as a typedef
TEST_CASE
(varid56);
//
function with a throw()
TEST_CASE
(varid57);
//
#6636: new scope by {}
TEST_CASE
(varid58);
//
#6638: for loop in for condition
TEST_CASE
(varid59);
//
#6696
TEST_CASE
(varid60);
//
#7267 cast '(unsigned x)10'
TEST_CASE
(varid61);
//
#4988 inline function
TEST_CASE
(varid62);
TEST_CASE
(varid63);
TEST_CASE
(varid_cpp_keywords_in_c_code);
TEST_CASE
(varid_cpp_keywords_in_c_code2);
//
#5373: varid=0 for argument called "delete"
TEST_CASE
(varidFunctionCall1);
TEST_CASE
(varidFunctionCall2);
TEST_CASE
(varidFunctionCall3);
TEST_CASE
(varidFunctionCall4);
//
ticket #3280
TEST_CASE
(varidFunctionCall5);
TEST_CASE
(varidStl);
TEST_CASE
(varidStl2);
TEST_CASE
(varid_newauto);
//
not declaration: new const auto(0);
TEST_CASE
(varid_delete);
TEST_CASE
(varid_functions);
TEST_CASE
(varid_sizeof);
TEST_CASE
(varid_reference_to_containers);
TEST_CASE
(varid_in_class1);
TEST_CASE
(varid_in_class2);
TEST_CASE
(varid_in_class3);
//
#3092 - shadow variable in member function
TEST_CASE
(varid_in_class4);
//
#3271 - public: class C;
TEST_CASE
(varid_in_class5);
//
#3584 - std::vector<::FOO::B> b;
TEST_CASE
(varid_in_class6);
//
#3755
TEST_CASE
(varid_in_class7);
//
set variable id for struct members
TEST_CASE
(varid_in_class9);
//
#4291 - id for variables accessed through 'this'
TEST_CASE
(varid_in_class10);
TEST_CASE
(varid_in_class11);
//
#4277 - anonymous union
TEST_CASE
(varid_in_class12);
//
#4637 - method
TEST_CASE
(varid_in_class13);
//
#4637 - method
TEST_CASE
(varid_in_class14);
TEST_CASE
(varid_in_class15);
//
#5533 - functions
TEST_CASE
(varid_in_class16);
TEST_CASE
(varid_in_class17);
//
#6056 - no varid for member functions
TEST_CASE
(varid_in_class18);
//
#7127
TEST_CASE
(varid_in_class19);
TEST_CASE
(varid_in_class20);
//
#7267
TEST_CASE
(varid_in_class21);
//
#7788
TEST_CASE
(varid_namespace_1);
//
#7272
TEST_CASE
(varid_namespace_2);
//
#7000
TEST_CASE
(varid_namespace_3);
//
#8627
TEST_CASE
(varid_initList);
TEST_CASE
(varid_initListWithBaseTemplate);
TEST_CASE
(varid_initListWithScope);
TEST_CASE
(varid_operator);
TEST_CASE
(varid_throw);
TEST_CASE
(varid_unknown_macro);
//
#2638 - unknown macro is not type
TEST_CASE
(varid_using);
//
ticket #3648
TEST_CASE
(varid_catch);
TEST_CASE
(varid_functionPrototypeTemplate);
TEST_CASE
(varid_templatePtr);
//
#4319
TEST_CASE
(varid_templateNamespaceFuncPtr);
//
#4172
TEST_CASE
(varid_templateArray);
TEST_CASE
(varid_templateParameter);
//
#7046 set varid for "X": std::array<int,X> Y;
TEST_CASE
(varid_templateUsing);
//
#5781 #7273
TEST_CASE
(varid_not_template_in_condition);
//
#7988
TEST_CASE
(varid_cppcast);
//
#6190
TEST_CASE
(varid_variadicFunc);
TEST_CASE
(varid_typename);
//
#4644
TEST_CASE
(varid_rvalueref);
TEST_CASE
(varid_arrayFuncPar);
//
#5294
TEST_CASE
(varid_sizeofPassed);
//
#5295
TEST_CASE
(varid_classInFunction);
//
#5293
TEST_CASE
(varid_pointerToArray);
//
#2645
TEST_CASE
(varid_cpp11initialization);
//
#4344
TEST_CASE
(varid_inheritedMembers);
//
#4101
TEST_CASE
(varid_header);
//
#6386
TEST_CASE
(varid_rangeBasedFor);
TEST_CASE
(varid_structinit);
//
#6406
TEST_CASE
(varid_arrayinit);
//
#7579
TEST_CASE
(varid_lambda_arg);
TEST_CASE
(varid_lambda_mutable);
TEST_CASE
(varid_trailing_return1);
//
#8889
TEST_CASE
(varid_trailing_return2);
//
#9066
TEST_CASE
(varid_parameter_pack);
//
#9383
TEST_CASE
(varidclass1);
TEST_CASE
(varidclass2);
TEST_CASE
(varidclass3);
TEST_CASE
(varidclass4);
TEST_CASE
(varidclass5);
TEST_CASE
(varidclass6);
TEST_CASE
(varidclass7);
TEST_CASE
(varidclass8);
TEST_CASE
(varidclass9);
TEST_CASE
(varidclass10);
//
variable declaration below usage
TEST_CASE
(varidclass11);
//
variable declaration below usage
TEST_CASE
(varidclass12);
TEST_CASE
(varidclass13);
TEST_CASE
(varidclass14);
TEST_CASE
(varidclass15);
//
initializer list
TEST_CASE
(varidclass16);
//
#4577
TEST_CASE
(varidclass17);
//
#6073
TEST_CASE
(varidclass18);
TEST_CASE
(varidclass19);
//
initializer list
TEST_CASE
(varid_classnameshaddowsvariablename);
//
#3990
TEST_CASE
(varidnamespace1);
TEST_CASE
(varidnamespace2);
TEST_CASE
(usingNamespace1);
TEST_CASE
(usingNamespace2);
TEST_CASE
(usingNamespace3);
TEST_CASE
(setVarIdStructMembers1);
TEST_CASE
(decltype1);
}
std::string
tokenize
(
const
char
code[],
bool
simplify =
false
,
const
char
filename[] =
"
test.cpp
"
) {
errout.
str
(
"
"
);
Settings settings;
settings.
platform
(Settings::Unix64);
settings.
standards
.
c
= Standards::
C89
;
settings.
standards
.
cpp
= Standards::
CPP11
;
Tokenizer
tokenizer
(&settings,
this
);
std::istringstream
istr
(code);
tokenizer.
tokenize
(istr, filename);
if
(simplify)
tokenizer.
simplifyTokenList2
();
//
result..
return
tokenizer.
tokens
()->
stringifyList
(
true
,
true
,
true
,
true
,
false
);
}
std::string
compareVaridsForVariable
(
const
char
code[],
const
char
varname[],
const
char
filename[] =
"
test.cpp
"
) {
errout.
str
(
"
"
);
Settings settings;
settings.
platform
(Settings::Unix64);
settings.
standards
.
c
= Standards::
C89
;
settings.
standards
.
cpp
= Standards::
CPP11
;
Tokenizer
tokenizer
(&settings,
this
);
std::istringstream
istr
(code);
tokenizer.
tokenize
(istr, filename);
unsigned
int
varid = ~
0U
;
for
(
const
Token *tok = tokenizer.
tokens
(); tok; tok = tok->
next
()) {
if
(tok->
str
() == varname) {
if
(varid == ~
0U
)
varid = tok->
varId
();
else
if
(varid != tok->
varId
())
return
std::string
(
"
Variable
"
) + varname +
"
has different varids:
\n
"
+ tokenizer.
tokens
()->
stringifyList
(
true
,
true
,
true
,
true
,
false
);
}
}
return
"
same varid
"
;
}
void
varid1
() {
{
const
std::string actual =
tokenize
(
"
static int i = 1;
\n
"
"
void f()
\n
"
"
{
\n
"
"
int i = 2;
\n
"
"
for (int i = 0; i < 10; ++i)
\n
"
"
i = 3;
\n
"
"
i = 4;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: static int i@1 = 1 ;
\n
"
"
2: void f ( )
\n
"
"
3: {
\n
"
"
4: int i@2 ; i@2 = 2 ;
\n
"
"
5: for ( int i@3 = 0 ; i@3 < 10 ; ++ i@3 ) {
\n
"
"
6: i@3 = 3 ; }
\n
"
"
7: i@2 = 4 ;
\n
"
"
8: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
{
const
std::string actual =
tokenize
(
"
static int i = 1;
\n
"
"
void f()
\n
"
"
{
\n
"
"
int i = 2;
\n
"
"
for (int i = 0; i < 10; ++i)
\n
"
"
{
\n
"
"
i = 3;
\n
"
"
}
\n
"
"
i = 4;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: static int i@1 = 1 ;
\n
"
"
2: void f ( )
\n
"
"
3: {
\n
"
"
4: int i@2 ; i@2 = 2 ;
\n
"
"
5: for ( int i@3 = 0 ; i@3 < 10 ; ++ i@3 )
\n
"
"
6: {
\n
"
"
7: i@3 = 3 ;
\n
"
"
8: }
\n
"
"
9: i@2 = 4 ;
\n
"
"
10: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
}
void
varid2
() {
const
std::string actual =
tokenize
(
"
void f()
\n
"
"
{
\n
"
"
struct ABC abc;
\n
"
"
abc.a = 3;
\n
"
"
i = abc.a;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void f ( )
\n
"
"
2: {
\n
"
"
3: struct ABC abc@1 ;
\n
"
"
4: abc@1 . a@2 = 3 ;
\n
"
"
5: i = abc@1 . a@2 ;
\n
"
"
6: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid3
() {
const
std::string actual =
tokenize
(
"
static char str[4];
\n
"
"
void f()
\n
"
"
{
\n
"
"
char str[10];
\n
"
"
str[0] = 0;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: static char str@1 [ 4 ] ;
\n
"
"
2: void f ( )
\n
"
"
3: {
\n
"
"
4: char str@2 [ 10 ] ;
\n
"
"
5: str@2 [ 0 ] = 0 ;
\n
"
"
6: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid4
() {
const
std::string actual =
tokenize
(
"
void f(const unsigned int a[])
\n
"
"
{
\n
"
"
int i = *(a+10);
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void f ( const unsigned int a@1 [ ] )
\n
"
"
2: {
\n
"
"
3: int i@2 ; i@2 = * ( a@1 + 10 ) ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid5
() {
const
std::string actual =
tokenize
(
"
void f()
\n
"
"
{
\n
"
"
int a,b;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void f ( )
\n
"
"
2: {
\n
"
"
3: int a@1 ; int b@2 ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid6
() {
const
std::string actual =
tokenize
(
"
int f(int a, int b)
\n
"
"
{
\n
"
"
return a+b;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: int f ( int a@1 , int b@2 )
\n
"
"
2: {
\n
"
"
3: return a@1 + b@2 ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid7
() {
const
std::string actual =
tokenize
(
"
void func() {
\n
"
"
char a[256] =
\"
test
\"
;
\n
"
"
{
\n
"
"
char b[256] =
\"
test
\"
;
\n
"
"
}
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void func ( ) {
\n
"
"
2: char a@1 [ 256 ] =
\"
test
\"
;
\n
"
"
3: {
\n
"
"
4: char b@2 [ 256 ] =
\"
test
\"
;
\n
"
"
5: }
\n
"
"
6: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varidReturn1
() {
const
std::string actual =
tokenize
(
"
int f()
\n
"
"
{
\n
"
"
int a;
\n
"
"
return a;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: int f ( )
\n
"
"
2: {
\n
"
"
3: int a@1 ;
\n
"
"
4: return a@1 ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varidReturn2
() {
const
std::string actual =
tokenize
(
"
void foo()
\n
"
"
{
\n
"
"
unsigned long mask = (1UL << size_) - 1;
\n
"
"
return (abits_val_ & mask);
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void foo ( )
\n
"
"
2: {
\n
"
"
3: unsigned long mask@1 ; mask@1 = ( 1UL << size_ ) - 1 ;
\n
"
"
4: return ( abits_val_ & mask@1 ) ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid8
() {
const
std::string actual =
tokenize
(
"
void func()
\n
"
"
{
\n
"
"
std::string str(
\"
test
\"
);
\n
"
"
str.clear();
\n
"
"
}
\n
"
);
const
char
expected[] =
"
1: void func ( )
\n
"
"
2: {
\n
"
"
3: std :: string str@1 (
\"
test
\"
) ;
\n
"
"
4: str@1 . clear ( ) ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid9
() {
const
std::string actual =
tokenize
(
"
typedef int INT32;
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: ;
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid10
() {
const
std::string actual =
tokenize
(
"
void foo()
\n
"
"
{
\n
"
"
int abc;
\n
"
"
struct abc abc1;
\n
"
"
}
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void foo ( )
\n
"
"
2: {
\n
"
"
3: int abc@1 ;
\n
"
"
4: struct abc abc1@2 ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid11
() {
const
std::string actual =
tokenize
(
"
class Foo;
\n
"
);
const
char
expected[] =
"
1: class Foo ;
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid12
() {
const
std::string actual =
tokenize
(
"
static void a()
\n
"
"
{
\n
"
"
class Foo *foo;
\n
"
"
}
\n
"
);
const
char
expected[] =
"
1: static void a ( )
\n
"
"
2: {
\n
"
"
3: class Foo * foo@1 ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid13
() {
const
std::string actual =
tokenize
(
"
void f()
\n
"
"
{
\n
"
"
int a; int b;
\n
"
"
a = a;
\n
"
"
}
\n
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void f ( )
\n
"
"
2: {
\n
"
"
3: int a@1 ; int b@2 ;
\n
"
"
4: a@1 = a@1 ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid14
() {
//
Overloaded operator*
const
std::string actual =
tokenize
(
"
void foo()
\n
"
"
{
\n
"
"
A a;
\n
"
"
B b;
\n
"
"
b * a;
\n
"
"
}
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: void foo ( )
\n
"
"
2: {
\n
"
"
3: A a@1 ;
\n
"
"
4: B b@2 ;
\n
"
"
5: b@2 * a@1 ;
\n
"
"
6: }
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
void
varid15
() {
{
const
std::string actual =
tokenize
(
"
struct S {
\n
"
"
struct T {
\n
"
"
} t;
\n
"
"
} s;
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: struct S {
\n
"
"
2: struct T {
\n
"
"
3: } ; struct T t@1 ;
\n
"
"
4: } ; struct S s@2 ;
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
{
const
std::string actual =
tokenize
(
"
struct S {
\n
"
"
struct T {
\n
"
"
} t;
\n
"
"
};
"
,
false
,
"
test.c
"
);
const
char
expected[] =
"
1: struct S {
\n
"
"
2: struct T {
\n
"
"
3: } ; struct T t@1 ;
\n
"
"
4: } ;
\n
"
;
ASSERT_EQUALS
(expected, actual);
}
}
void
varid16
() {
const
char
code[] =
"
void foo()
\n
"
"
{
\n
"
"
int x = 1;
\n
"
"
y = (z * x);
\n
"
"
}
\n
"
;
const
char
expected[] =
"
1: void foo ( )
\n
"
"
2: {
\n
"
"
3: int x@1 ; x@1 = 1 ;
\n
"
"
4: y = z * x@1 ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code,
false
,
"
test.c
"
));
}
void
varid17
() {
//
ticket #1810
const
char
code[] =
"
char foo()
\n
"
"
{
\n
"
"
char c('c');
\n
"
"
return c;
\n
"
"
}
\n
"
;
const
char
expected[] =
"
1: char foo ( )
\n
"
"
2: {
\n
"
"
3: char c@1 ( 'c' ) ;
\n
"
"
4: return c@1 ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code,
false
,
"
test.c
"
));
}
void
varid18
() {
const
char
code[] =
"
char foo(char c)
\n
"
"
{
\n
"
"
bar::c = c;
\n
"
"
}
\n
"
;
const
char
expected[] =
"
1: char foo ( char c@1 )
\n
"
"
2: {
\n
"
"
3: bar :: c = c@1 ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid19
() {
const
char
code[] =
"
void foo()
\n
"
"
{
\n
"
"
std::pair<std::vector<double>, int> x;
\n
"
"
}
\n
"
;
const
char
expected[] =
"
1: void foo ( )
\n
"
"
2: {
\n
"
"
3: std :: pair < std :: vector < double > , int > x@1 ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid20
() {
const
char
code[] =
"
void foo()
\n
"
"
{
\n
"
"
pair<vector<int>, vector<double> > x;
\n
"
"
}
\n
"
;
const
char
expected[] =
"
1: void foo ( )
\n
"
"
2: {
\n
"
"
3: pair < vector < int > , vector < double > > x@1 ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid24
() {
const
char
code[] =
"
class foo()
\n
"
"
{
\n
"
"
public:
\n
"
"
;
\n
"
"
private:
\n
"
"
static int i;
\n
"
"
};
\n
"
;
const
char
expected[] =
"
1: class foo ( )
\n
"
"
2: {
\n
"
"
3: public:
\n
"
"
4: ;
\n
"
"
5: private:
\n
"
"
6: static int i@1 ;
\n
"
"
7: } ;
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid25
() {
const
char
code[] =
"
class foo()
\n
"
"
{
\n
"
"
public:
\n
"
"
;
\n
"
"
private:
\n
"
"
mutable int i;
\n
"
"
};
\n
"
;
const
char
expected[] =
"
1: class foo ( )
\n
"
"
2: {
\n
"
"
3: public:
\n
"
"
4: ;
\n
"
"
5: private:
\n
"
"
6: mutable int i@1 ;
\n
"
"
7: } ;
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid26
() {
const
char
code[] =
"
list<int (*)()> functions;
\n
"
;
const
char
expected[] =
"
1: list < int ( * ) ( ) > functions@1 ;
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid27
() {
const
char
code[] =
"
int fooled_ya;
\n
"
"
fooled_ya::iterator iter;
\n
"
;
const
char
expected[] =
"
1: int fooled_ya@1 ;
\n
"
"
2: fooled_ya :: iterator iter@2 ;
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid28
() {
//
ticket #2630 (segmentation fault)
ASSERT_THROW
(
tokenize
(
"
template <typedef A>
\n
"
), InternalError);
}
void
varid29
() {
const
char
code[] =
"
class A {
\n
"
"
B<C<1>,1> b;
\n
"
"
};
\n
"
;
const
char
expected[] =
"
1: class A {
\n
"
"
2: B < C < 1 > , 1 > b@1 ;
\n
"
"
3: } ;
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
}
void
varid30
() {
//
ticket #2614
const
char
code1[] =
"
void f(EventPtr *eventP, ActionPtr **actionsP)
\n
"
"
{
\n
"
"
EventPtr event = *eventP;
\n
"
"
*actionsP = &event->actions;
\n
"
"
}
\n
"
;
const
char
expected1[] =
"
1: void f ( EventPtr * eventP@1 , ActionPtr * * actionsP@2 )
\n
"
"
2: {
\n
"
"
3: EventPtr event@3 ; event@3 = * eventP@1 ;
\n
"
"
4: * actionsP@2 = & event@3 . actions@4 ;
\n
"
"
5: }
\n
"
;
ASSERT_EQUALS
(expected1,
tokenize
(code1,
false
,
"
test.c
"
));
const
char
code2[] =
"
void f(int b, int c) {
\n
"
"
x(a*b*c,10);
\n
"
"
}
\n
"
;
const
char
expected2[] =
"
1: void f ( int b@1 , int c@2 ) {
\n
"
"
2: x ( a * b@1 * c@2 , 10 ) ;
\n
"
"
3: }
\n
"
;
ASSERT_EQUALS
(expected2,
tokenize
(code2,
false
,
"
test.c
"
));
const
char
code3[] =
"
class Nullpointer : public ExecutionPath
\n
"
"
{
\n
"
"
Nullpointer(Check *c, const unsigned int id, const std::string &name)
\n
"
"
: ExecutionPath(c, id)
\n
"
"
{
\n
"
"
}
\n
"
"
}
\n
"
;
const
char
expected3[] =
"
1: class Nullpointer : public ExecutionPath
\n
"
"
2: {
\n
"
"
3: Nullpointer ( Check * c@1 , const unsigned int id@2 , const std :: string & name@3 )
\n
"
"
4: : ExecutionPath ( c@1 , id@2 )
\n
"
"
5: {
\n
"
"
6: }
\n
"
"
7: }
\n
"
;
ASSERT_EQUALS
(expected3,
tokenize
(code3));
}
void
varid34
() {
//
ticket #2825
const
char
code[] =
"
class Fred : public B1, public B2
\n
"
"
{
\n
"
"
public:
\n
"
"
Fred() { a = 0; }
\n
"
"
private:
\n
"
"
int a;
\n
"
"
};
\n
"
;
const
char
expected[] =
"
1: class Fred : public B1 , public B2
\n
"
"
2: {
\n
"
"
3: public:
\n
"
"
4: Fred ( ) { a@1 = 0 ; }
\n
"
"
5: private:
\n
"
"
6: int a@1 ;
\n
"
"
7: } ;
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
ASSERT_EQUALS
(
"
"
, errout.
str
());
}
void
varid35
() {
//
function declaration inside function body
//
#2937
const
char
code[] =
"
int foo() {
\n
"
"
int f(x);
\n
"
"
return f;
\n
"
"
}
\n
"
;
const
char
expected[] =
"
1: int foo ( ) {
\n
"
"
2: int f@1 ( x ) ;
\n
"
"
3: return f@1 ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code));
//
#4627
const
char
code2[] =
"
void f() {
\n
"
"
int *p;
\n
"
"
void bar(int *p);
\n
"
"
}
"
;
const
char
expected2[] =
"
1: void f ( ) {
\n
"
"
2: int * p@1 ;
\n
"
"
3: void bar ( int * p ) ;
\n
"
"
4: }
\n
"
;
ASSERT_EQUALS
(expected2,
tokenize
(code2));
//
#7740
const
char
code3[] =
"
Float f(float scale) {
\n
"
"
return Float(val * scale);
\n
"
"
}
\n
"
;
const
char
expected3[] =
"
1: Float f ( float scale@1 ) {
\n
"
"
2: return Float ( val * scale@1 ) ;
\n
"
"
3: }
\n
"
;
ASSERT_EQUALS
(expected3,
tokenize
(code3));
}
void
varid36
() {
//
ticket #2980 (segmentation fault)
const
char
code[] =
"
#elif A
\n
"
"
A,a<b<x0
\n
"
;
tokenize
(code);
ASSERT_EQUALS
(
"
"
, errout.
str
());
}
void
varid37
() {
{
const
char
code[] =
"
void blah() {
"
"
Bar bar(*x);
"
"
}
"
;
ASSERT_EQUALS
(
"
1: void blah ( ) { Bar bar@1 ( * x ) ; }
\n
"
,
tokenize
(code));
}
{
const
char
code[] =
"
void blah() {
"
"
Bar bar(&x);
"
"
}
"
;
ASSERT_EQUALS
(
"
1: void blah ( ) { Bar bar@1 ( & x ) ; }
\n
"
,
tokenize
(code));
}
}
void
varid38
() {
const
char
code[] =
"
FOO class C;
\n
"
;
ASSERT_EQUALS
(
"
1: FOO class C ;
\n
"
,
tokenize
(code));
}
void
varid39
() {
//
const..
{
const
char
code[] =
"
void f(FOO::BAR const);
\n
"
;
ASSERT_EQUALS
(
"
1: void f ( const FOO :: BAR ) ;
\n
"
,
tokenize
(code));
}
{
const
char
code[] =
"
static int const SZ = 22;
\n
"
;
ASSERT_EQUALS
(
"
1: static const int SZ@1 = 22 ;
\n
"
,
tokenize
(code,
false
,
"
test.c
"
));
}
}
void
varid40
() {
const
char
code[] =
"
extern
\"
C
\"
int (*a())();
"
;
ASSERT_EQUALS
(
"
1: int * a ( ) ;
\n
"
,
tokenize
(code));
}
void
varid41
() {
const
char
code1[] =
"
union evt; void f(const evt & event);
"
;
ASSERT_EQUALS
(
"
1: union evt ; void f ( const evt & event@1 ) ;
\n
"
,
tokenize
(code1,
false
,
"
test.c
"
));
const
char
code2[] =
"
struct evt; void f(const evt & event);
"
;
ASSERT_EQUALS
(
"
1: struct evt ; void f ( const evt & event@1 ) ;
\n
"
,
tokenize
(code2,
false
,
"
test.c
"
));
}
void
varid42
() {
const
char
code[] =
"
namespace fruit { struct banana {}; };
\n
"
"
class Fred {
\n
"
"
public:
\n
"
"
struct fruit::banana Bananas[25];
\n
"
"
};
"
;
ASSERT_EQUALS
(
"
1: namespace fruit { struct banana { } ; } ;
\n
"
"
2: class Fred {
\n
"
"
3: public:
\n
"
"
4: struct fruit :: banana Bananas@1 [ 25 ] ;
\n
"
"
5: } ;
\n
"
,
tokenize
(code));
}
void
varid43
() {
const
char
code[] =
"
int main(int flag) { if(a & flag) { return 1; } }
"
;
ASSERT_EQUALS
(
"
1: int main ( int flag@1 ) { if ( a & flag@1 ) { return 1 ; } }
\n
"
,
tokenize
(code,
false
,
"
test.c
"
));
}
void
varid44
() {
const
char
code[] =
"
class A:public B,public C,public D {};
"
;
ASSERT_EQUALS
(
"
1: class A : public B , public C , public D { } ;
\n
"
,
tokenize
(code));
}
void
varid45
() {
//
#3466
const
char
code[] =
"
void foo() { B b(this); A a(this, b); }
"
;
ASSERT_EQUALS
(
"
1: void foo ( ) { B b@1 ( this ) ; A a@2 ( this , b@1 ) ; }
\n
"
,
tokenize
(code));
}
void
varid46
() {
//
#3756
const
char
code[] =
"
void foo() { int t; x = (struct t *)malloc(); f(t); }
"
;
ASSERT_EQUALS
(
"
1: void foo ( ) { int t@1 ; x = ( struct t * ) malloc ( ) ; f ( t@1 ) ; }
\n
"
,
tokenize
(code,
false
,
"
test.c
"
));
}
void
varid47
() {
//
function parameters
//
#3768
{
const
char
code[] =
"
void f(std::string &string, std::string &len) {}
"
;
ASSERT_EQUALS
(
"
1: void f ( std :: string & string@1 , std :: string & len@2 ) { }
\n
"
,
tokenize
(code,
false
,
"
test.cpp
"
));
}
//
#4729
{
const
char
code[] =
"
int x;
\n
"
"
void a(int x);
\n
"
"
void b() { x = 0; }
\n
"
;
ASSERT_EQUALS
(
"
1: int x@1 ;
\n
"
"
2: void a ( int x@2 ) ;
\n
"
"
3: void b ( ) { x@1 = 0 ; }
\n
"
,
tokenize
(code));
}
}
void
varid48
() {
//
#3785 - return (a*b)
const
char
code[] =
"
int X::f(int b) const { return(a*b); }
"
;
ASSERT_EQUALS
(
"
1: int X :: f ( int b@1 ) const { return ( a * b@1 ) ; }
\n
"
,
tokenize
(code,
false
));
}
void
varid49
() {
//
#3799 - void f(std::vector<int>)
const
char
code[] =
"
void f(std::vector<int>)
"
;
ASSERT_EQUALS
(
"
1: void f ( std :: vector < int > )
\n
"
,
tokenize
(code,
false
,
"
test.cpp
"
));
}
void
varid50
() {
//
#3760 - explicit
const
char
code[] =
"
class A { explicit A(const A&); };
"
;
ASSERT_EQUALS
(
"
1: class A { explicit A ( const A & ) ; } ;
\n
"
,
tokenize
(code,
false
,
"
test.cpp
"
));
}
void
varid51
() {
//
don't set varid on template function
const
char
code[] =
"
T t; t.x<0>();
"
;
ASSERT_EQUALS
(
"
1: T t@1 ; t@1 . x < 0 > ( ) ;
\n
"
,
tokenize
(code,
false
,
"
test.cpp
"
));
}
void
varid52
() {
const
char
code[] =
"
A<B<C>::D> e;
\n
"
"
B< C<> > b[10];
\n
"
"
B<C<>> c[10];
"
;
ASSERT_EQUALS
(
"
1: A < B < C > :: D > e@1 ;
\n
"
"
2: B < C < > > b@2 [ 10 ] ;
\n
"
"
3: B < C < > > c@3 [ 10 ] ;
\n
"
,
tokenize
(code,
false
,
"
test.cpp
"
));
}
void
varid53
() {
//
#4172 - Template instantiation: T<&functionName> list[4];
ASSERT_EQUALS
(
"
1: A < & f > list@1 [ 4 ] ;
\n
"
,
tokenize
(
"
A<&f> list[4];
"
,
false
,
"
test.cpp
"
));
}
void
varid54
() {
//
hang
//
Original source code: libgc
tokenize
(
"
STATIC ptr_t GC_approx_sp(void) { word sp; sp = (word)&sp; return((ptr_t)sp); }
"
,
true
);
}
void
varid55
() {
//
Ticket #5868
const
char
code[] =
"
typedef struct foo {} foo;
"
"
void bar1(struct foo foo) {}
"
"
void baz1(foo foo) {}
"
"
void bar2(struct foo& foo) {}
"
"
void baz2(foo& foo) {}
"
"
void bar3(struct foo* foo) {}
"
"
void baz3(foo* foo) {}
"
;
const
char
expected[] =
"
1:
"
"
struct foo { } ;
"
"
void bar1 ( struct foo foo@1 ) { }
"
"
void baz1 ( struct foo foo@2 ) { }
"
"
void bar2 ( struct foo & foo@3 ) { }
"
"
void baz2 ( struct foo & foo@4 ) { }
"
"
void bar3 ( struct foo * foo@5 ) { }
"
"
void baz3 ( struct foo * foo@6 ) { }
\n
"
;
ASSERT_EQUALS
(expected,
tokenize
(code,
false
,
"
test.cpp
"
));
}
void
varid56
() {
//
Ticket #6548 - function with a throw()
const
char
code1[] =
"
void fred(int x) throw() {}
"
"
void wilma() { x++; }
"
;
const
char
expected1[] =
"
1:
"
"
void fred ( int x@1 ) throw ( ) { }
"
"
void wilma ( ) { x ++ ; }
\n
"
;
ASSERT_EQUALS
(expected1,
tokenize
(code1,
false
,
"
test.cpp
"
));
const
char
code2[] =
"
void fred(int x) const throw(EXCEPT) {}
"
"
void wilma() { x++; }
"
;
const
char
expected2[] =
"
1:
"
"
void fred ( int x@1 ) const throw ( EXCEPT ) { }
"
"
void wilma ( ) { x ++ ; }
\n
"
;
ASSERT_EQUALS
(expected2,
tokenize
(code2,
false
,
"
test.cpp
"
));
const
char
code3[] =
"
void fred(int x) throw() ABCD {}
"
"
void wilma() { x++; }
"
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL