@@ -76,6 +76,7 @@ class TestSimplifyUsing : public TestFixture {
7676 TEST_CASE (simplifyUsing9518);
7777 TEST_CASE (simplifyUsing9757);
7878 TEST_CASE (simplifyUsing10008);
79+ TEST_CASE (simplifyUsing10054);
7980 }
8081
8182 std::string tok (const char code[], bool simplify = true , Settings::PlatformType type = Settings::Native, bool debugwarnings = true ) {
@@ -663,6 +664,205 @@ class TestSimplifyUsing : public TestFixture {
663664 " }" ;
664665 ASSERT_EQUALS (exp, tok (code, false ));
665666 }
667+
668+ void simplifyUsing10054 () { // debug: Executable scope 'x' with unknown function.
669+ {
670+ // original example: using "namespace external::ns1;" but redundant qualification
671+ const char code[] = " namespace external {\n "
672+ " namespace ns1 {\n "
673+ " template <int size> struct B { };\n "
674+ " using V = B<sizeof(bool)>;\n "
675+ " }\n "
676+ " }\n "
677+ " namespace ns {\n "
678+ " struct A {\n "
679+ " void f(external::ns1::V);\n "
680+ " };\n "
681+ " }\n "
682+ " using namespace external::ns1;\n "
683+ " namespace ns {\n "
684+ " void A::f(external::ns1::V) {}\n "
685+ " }" ;
686+ const char exp[] = " namespace external { "
687+ " namespace ns1 { "
688+ " struct B<1> ; "
689+ " } "
690+ " } "
691+ " namespace ns { "
692+ " struct A { "
693+ " void f ( external :: ns1 :: B<1> ) ; "
694+ " } ; "
695+ " } "
696+ " using namespace external :: ns1 ; "
697+ " namespace ns { "
698+ " void A :: f ( external :: ns1 :: B<1> ) { } "
699+ " } "
700+ " struct external :: ns1 :: B<1> { } ;" ;
701+ ASSERT_EQUALS (exp, tok (code, true ));
702+ ASSERT_EQUALS (" " , errout.str ());
703+ }
704+ {
705+ // no using "namespace external::ns1;"
706+ const char code[] = " namespace external {\n "
707+ " namespace ns1 {\n "
708+ " template <int size> struct B { };\n "
709+ " using V = B<sizeof(bool)>;\n "
710+ " }\n "
711+ " }\n "
712+ " namespace ns {\n "
713+ " struct A {\n "
714+ " void f(external::ns1::V);\n "
715+ " };\n "
716+ " }\n "
717+ " namespace ns {\n "
718+ " void A::f(external::ns1::V) {}\n "
719+ " }" ;
720+ const char exp[] = " namespace external { "
721+ " namespace ns1 { "
722+ " struct B<1> ; "
723+ " } "
724+ " } "
725+ " namespace ns { "
726+ " struct A { "
727+ " void f ( external :: ns1 :: B<1> ) ; "
728+ " } ; "
729+ " } "
730+ " namespace ns { "
731+ " void A :: f ( external :: ns1 :: B<1> ) { } "
732+ " } "
733+ " struct external :: ns1 :: B<1> { } ;" ;
734+ ASSERT_EQUALS (exp, tok (code, true ));
735+ ASSERT_EQUALS (" " , errout.str ());
736+ }
737+ {
738+ // using "namespace external::ns1;" without redundant qualification
739+ const char code[] = " namespace external {\n "
740+ " namespace ns1 {\n "
741+ " template <int size> struct B { };\n "
742+ " using V = B<sizeof(bool)>;\n "
743+ " }\n "
744+ " }\n "
745+ " namespace ns {\n "
746+ " struct A {\n "
747+ " void f(external::ns1::V);\n "
748+ " };\n "
749+ " }\n "
750+ " using namespace external::ns1;\n "
751+ " namespace ns {\n "
752+ " void A::f(V) {}\n "
753+ " }" ;
754+ const char exp[] = " namespace external { "
755+ " namespace ns1 { "
756+ " struct B<1> ; "
757+ " } "
758+ " } "
759+ " namespace ns { "
760+ " struct A { "
761+ " void f ( external :: ns1 :: B<1> ) ; "
762+ " } ; "
763+ " } "
764+ " using namespace external :: ns1 ; "
765+ " namespace ns { "
766+ " void A :: f ( external :: ns1 :: B<1> ) { } "
767+ " } "
768+ " struct external :: ns1 :: B<1> { } ;" ;
769+ ASSERT_EQUALS (exp, tok (code, true ));
770+ ASSERT_EQUALS (" " , errout.str ());
771+ }
772+ {
773+ // using "namespace external::ns1;" without redundant qualification on declaration and definition
774+ const char code[] = " namespace external {\n "
775+ " namespace ns1 {\n "
776+ " template <int size> struct B { };\n "
777+ " using V = B<sizeof(bool)>;\n "
778+ " }\n "
779+ " }\n "
780+ " using namespace external::ns1;\n "
781+ " namespace ns {\n "
782+ " struct A {\n "
783+ " void f(V);\n "
784+ " };\n "
785+ " }\n "
786+ " namespace ns {\n "
787+ " void A::f(V) {}\n "
788+ " }" ;
789+ const char exp[] = " namespace external { "
790+ " namespace ns1 { "
791+ " struct B<1> ; "
792+ " } "
793+ " } "
794+ " using namespace external :: ns1 ; "
795+ " namespace ns { "
796+ " struct A { "
797+ " void f ( external :: ns1 :: B<1> ) ; "
798+ " } ; "
799+ " } "
800+ " namespace ns { "
801+ " void A :: f ( external :: ns1 :: B<1> ) { } "
802+ " } "
803+ " struct external :: ns1 :: B<1> { } ;" ;
804+ ASSERT_EQUALS (exp, tok (code, true ));
805+ ASSERT_EQUALS (" " , errout.str ());
806+ }
807+ {
808+ const char code[] = " namespace external {\n "
809+ " template <int size> struct B { };\n "
810+ " namespace ns1 {\n "
811+ " using V = B<sizeof(bool)>;\n "
812+ " }\n "
813+ " }\n "
814+ " namespace ns {\n "
815+ " struct A {\n "
816+ " void f(external::ns1::V);\n "
817+ " };\n "
818+ " }\n "
819+ " namespace ns {\n "
820+ " void A::f(external::ns1::V) {}\n "
821+ " }" ;
822+ const char exp[] = " namespace external { "
823+ " struct B<1> ; "
824+ " } "
825+ " namespace ns { "
826+ " struct A { "
827+ " void f ( external :: B<1> ) ; "
828+ " } ; "
829+ " } "
830+ " namespace ns { "
831+ " void A :: f ( external :: B<1> ) { } "
832+ " } "
833+ " struct external :: B<1> { } ;" ;
834+ ASSERT_EQUALS (exp, tok (code, true ));
835+ ASSERT_EQUALS (" " , errout.str ());
836+ }
837+ {
838+ const char code[] = " template <int size> struct B { };\n "
839+ " namespace external {\n "
840+ " namespace ns1 {\n "
841+ " using V = B<sizeof(bool)>;\n "
842+ " }\n "
843+ " }\n "
844+ " namespace ns {\n "
845+ " struct A {\n "
846+ " void f(external::ns1::V);\n "
847+ " };\n "
848+ " }\n "
849+ " namespace ns {\n "
850+ " void A::f(external::ns1::V) {}\n "
851+ " }" ;
852+ const char exp[] = " struct B<1> ; "
853+ " namespace ns { "
854+ " struct A { "
855+ " void f ( B<1> ) ; "
856+ " } ; "
857+ " } "
858+ " namespace ns { "
859+ " void A :: f ( B<1> ) { } "
860+ " } "
861+ " struct B<1> { } ;" ;
862+ ASSERT_EQUALS (exp, tok (code, true ));
863+ ASSERT_EQUALS (" " , errout.str ());
864+ }
865+ }
666866};
667867
668868REGISTER_TEST (TestSimplifyUsing)
0 commit comments