@@ -80,6 +80,10 @@ class TestSimplifyUsing : public TestFixture {
8080 TEST_CASE (simplifyUsing40);
8181 TEST_CASE (simplifyUsing41);
8282 TEST_CASE (simplifyUsing42);
83+ TEST_CASE (simplifyUsing43);
84+ TEST_CASE (simplifyUsing44);
85+ TEST_CASE (simplifyUsing45);
86+ TEST_CASE (simplifyUsing46);
8387
8488 TEST_CASE (simplifyUsing8970);
8589 TEST_CASE (simplifyUsing8971);
@@ -991,6 +995,90 @@ class TestSimplifyUsing : public TestFixture {
991995 }
992996 }
993997
998+ void simplifyUsing43 () {
999+ // injected-class-name must not be replaced
1000+ const char code[] = " namespace N {\n "
1001+ " class C {\n "
1002+ " C(int* p) : p(p) {}\n "
1003+ " ~C() { unref(p); }\n "
1004+ " C& operator=(const C& other);\n "
1005+ " int* p;\n "
1006+ " };\n "
1007+ " }\n "
1008+ " using N::C;\n "
1009+ " C c;\n " ;
1010+ const char expected[] = " namespace N { "
1011+ " class C { "
1012+ " C ( int * p ) : p ( p ) { } "
1013+ " ~ C ( ) { unref ( p ) ; } "
1014+ " C & operator= ( const C & other ) ; "
1015+ " int * p ; "
1016+ " } ; "
1017+ " } "
1018+ " N :: C c ;" ;
1019+ ASSERT_EQUALS (expected, tok (code));
1020+ ASSERT_EQUALS (" " , errout_str ());
1021+ }
1022+
1023+ void simplifyUsing44 () {
1024+ // injected-class-name must not be replaced, class defined with qualified name
1025+ const char code[] = " namespace N { class C; }\n "
1026+ " class N::C {\n "
1027+ " C(int* p) : p(p) {}\n "
1028+ " ~C() { unref(p); }\n "
1029+ " C& operator=(const C& other);\n "
1030+ " int* p;\n "
1031+ " };\n "
1032+ " using N::C;\n "
1033+ " C c;\n " ;
1034+ const char expected[] = " namespace N { class C ; } "
1035+ " class N :: C { "
1036+ " C ( int * p ) : p ( p ) { } "
1037+ " ~ C ( ) { unref ( p ) ; } "
1038+ " C & operator= ( const C & other ) ; "
1039+ " int * p ; "
1040+ " } ; "
1041+ " N :: C c ;" ;
1042+ ASSERT_EQUALS (expected, tok (code));
1043+ ASSERT_EQUALS (" " , errout_str ());
1044+ }
1045+
1046+ void simplifyUsing45 () {
1047+ // destructor name must not be replaced in out-of-line destructor
1048+ const char code[] = " namespace N {\n "
1049+ " class C {\n "
1050+ " public:\n "
1051+ " C();\n "
1052+ " ~C();\n "
1053+ " int* p;\n "
1054+ " };\n "
1055+ " }\n "
1056+ " using N::C;\n "
1057+ " N::C::C() : p(new int) {}\n "
1058+ " N::C::~C() { delete p; }\n " ;
1059+ const char expected[] = " namespace N { "
1060+ " class C { "
1061+ " public: "
1062+ " C ( ) ; "
1063+ " ~ C ( ) ; "
1064+ " int * p ; "
1065+ " } ; "
1066+ " } "
1067+ " N :: C :: C ( ) : p ( new int ) { } "
1068+ " N :: C :: ~ C ( ) { delete p ; }" ;
1069+ ASSERT_EQUALS (expected, tok (code));
1070+ ASSERT_EQUALS (" " , errout_str ());
1071+ }
1072+
1073+ void simplifyUsing46 () {
1074+ // alias after unary bitwise not must be replaced
1075+ const char code[] = " using U = unsigned char;\n "
1076+ " unsigned f() { return ~U(0) & ~U{1} & ~U(); }\n " ;
1077+ const char expected[] = " unsigned int f ( ) { return ~ unsigned char ( 0 ) & ~ unsigned char { 1 } & ~ unsigned char ( ) ; }" ;
1078+ ASSERT_EQUALS (expected, tok (code));
1079+ ASSERT_EQUALS (" " , errout_str ());
1080+ }
1081+
9941082 void simplifyUsing8970 () {
9951083 const char code[] = " using V = std::vector<int>;\n "
9961084 " struct A {\n "
0 commit comments