@@ -42,7 +42,7 @@ class TestSimplifyTypedef : public TestFixture {
4242private:
4343 // If there are unused templates, keep those
4444 const Settings settings0 = settingsBuilder().severity(Severity::style).checkUnusedTemplates().build();
45- const Settings settings1 = settingsBuilder().checkUnusedTemplates().build();
45+ const Settings settings1 = settingsBuilder().severity(Severity::portability). checkUnusedTemplates().build();
4646 const Settings settings2 = settingsBuilder().severity(Severity::style).checkUnusedTemplates().build();
4747
4848 void run () override {
@@ -57,6 +57,9 @@ class TestSimplifyTypedef : public TestFixture {
5757 TEST_CASE (cstruct3);
5858 TEST_CASE (cstruct3);
5959 TEST_CASE (cstruct4);
60+ TEST_CASE (cfunction1);
61+ TEST_CASE (cfunction2);
62+ TEST_CASE (cfunction3);
6063 TEST_CASE (cfp1);
6164 TEST_CASE (cfp2);
6265 TEST_CASE (cfp4);
@@ -382,6 +385,26 @@ class TestSimplifyTypedef : public TestFixture {
382385 ASSERT_EQUALS (" struct s { int a ; int b ; } ; struct s x { } ;" , simplifyTypedefC (code));
383386 }
384387
388+ void cfunction1 () {
389+ const char code[] = " typedef int callback(int);\n "
390+ " callback* cb;" ;
391+ ASSERT_EQUALS (" int ( * cb ) ( int ) ;" , simplifyTypedefC (code));
392+ }
393+
394+ void cfunction2 () {
395+ const char code[] = " typedef int callback(int);\n "
396+ " typedef callback* callbackPtr;\n "
397+ " callbackPtr cb;" ;
398+ ASSERT_EQUALS (" int ( * cb ) ( int ) ;" , simplifyTypedefC (code));
399+ }
400+
401+ void cfunction3 () {
402+ const char code[] = " typedef int f(int);\n "
403+ " typedef const f cf;\n " ;
404+ simplifyTypedefC (code);
405+ ASSERT_EQUALS (" [file.c:2]: (portability) It is unspecified behavior to const qualify a function type.\n " , errout.str ());
406+ }
407+
385408 void cfp1 () {
386409 const char code[] = " typedef void (*fp)(void * p);\n "
387410 " fp x;" ;
@@ -3532,7 +3555,7 @@ class TestSimplifyTypedef : public TestFixture {
35323555 " func7 f7;" ;
35333556
35343557 // The expected result..
3535- const char expected[] = " ; C f1 ( ) ; "
3558+ const char expected[] = " C f1 ( ) ; "
35363559 " C ( * f2 ) ( ) ; "
35373560 " C ( & f3 ) ( ) ; "
35383561 " C ( * f4 ) ( ) ; "
@@ -3561,7 +3584,7 @@ class TestSimplifyTypedef : public TestFixture {
35613584
35623585 // The expected result..
35633586 // C const -> const C
3564- const char expected[] = " ; const C f1 ( ) ; "
3587+ const char expected[] = " const C f1 ( ) ; "
35653588 " const C ( * f2 ) ( ) ; "
35663589 " const C ( & f3 ) ( ) ; "
35673590 " const C ( * f4 ) ( ) ; "
@@ -3589,7 +3612,7 @@ class TestSimplifyTypedef : public TestFixture {
35893612 " func7 f7;" ;
35903613
35913614 // The expected result..
3592- const char expected[] = " ; const C f1 ( ) ; "
3615+ const char expected[] = " const C f1 ( ) ; "
35933616 " const C ( * f2 ) ( ) ; "
35943617 " const C ( & f3 ) ( ) ; "
35953618 " const C ( * f4 ) ( ) ; "
@@ -3617,7 +3640,7 @@ class TestSimplifyTypedef : public TestFixture {
36173640 " func7 f7;" ;
36183641
36193642 // The expected result..
3620- const char expected[] = " ; C * f1 ( ) ; "
3643+ const char expected[] = " C * f1 ( ) ; "
36213644 " C * ( * f2 ) ( ) ; "
36223645 " C * ( & f3 ) ( ) ; "
36233646 " C * ( * f4 ) ( ) ; "
@@ -3645,7 +3668,7 @@ class TestSimplifyTypedef : public TestFixture {
36453668 " func7 f7;" ;
36463669
36473670 // The expected result..
3648- const char expected[] = " ; const C * f1 ( ) ; "
3671+ const char expected[] = " const C * f1 ( ) ; "
36493672 " const C * ( * f2 ) ( ) ; "
36503673 " const C * ( & f3 ) ( ) ; "
36513674 " const C * ( * f4 ) ( ) ; "
@@ -3674,7 +3697,7 @@ class TestSimplifyTypedef : public TestFixture {
36743697
36753698 // The expected result..
36763699 // C const -> const C
3677- const char expected[] = " ; const C * f1 ( ) ; "
3700+ const char expected[] = " const C * f1 ( ) ; "
36783701 " const C * ( * f2 ) ( ) ; "
36793702 " const C * ( & f3 ) ( ) ; "
36803703 " const C * ( * f4 ) ( ) ; "
0 commit comments