Bug 94310 - using constructor inheritance breaks the code
Summary: using constructor inheritance breaks the code
Status: RESOLVED DUPLICATE of bug 80417
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.1
: P3 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2020-03-24 19:51 UTC by tilin97
Modified: 2021-12-09 05:52 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-04-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tilin97 2020-03-24 19:51:42 UTC
The following code is compiled without errors

template<typename>
struct B {
};

template<typename... Types>
struct A : public B<Types>... {
    using B<Types>::operator=...;
    using B<Types>::B...;
};

int main() {}

But when you change the order of using declarations compilation fails (the same error occurs in all versions of gcc on godbolt.org)

template<typename>
struct B {
};

template<typename... Types>
struct A : public B<Types>... {
    using B<Types>::B...;                <---
    using B<Types>::operator=...;        <---
};

int main() {}

gcc -v -std=c++17 -Wall -Wextra main.cpp
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.2.1-17ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.2.1 20191102 (Ubuntu 9.2.1-17ubuntu1~18.04.1) 
COLLECT_GCC_OPTIONS='-v' '-std=c++17' '-Wall' '-Wextra' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/9/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -Wall -Wextra -std=c++17 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat-security -o /tmp/ccVHNdqy.s
GNU C++17 (Ubuntu 9.2.1-17ubuntu1~18.04.1) version 9.2.1 20191102 (x86_64-linux-gnu)
        compiled by GNU C version 9.2.1 20191102, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/9"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/9
 /usr/include/x86_64-linux-gnu/c++/9
 /usr/include/c++/9/backward
 /usr/lib/gcc/x86_64-linux-gnu/9/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/9/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++17 (Ubuntu 9.2.1-17ubuntu1~18.04.1) version 9.2.1 20191102 (x86_64-linux-gnu)
        compiled by GNU C version 9.2.1 20191102, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 33caeb1da5df6f896d4e495951c13eae
main.cpp:8:11: error: expected nested-name-specifier before ‘B’
    8 |     using B<Types>::operator=...;
      |           ^


-----------------------------

The following code is also compiled with an error if there is no comment

template<typename T>
struct B {
	void foo() {}
};

template<typename... Types>
struct A : public B<Types>... {
	// using B<Types>::B...;      <---

	void bar() {
		(B<Types>::foo() , ...);
	}
};

int main() {}

gcc -std=c++17 -Wall -Wextra b.cpp
b.cpp: In member function ‘void A<Types>::bar()’:
b.cpp:11:11: error: expected primary-expression before ‘>’ token
   11 |   (B<Types>::foo() , ...);
      |           ^
b.cpp:11:14: error: ‘::foo’ has not been declared
   11 |   (B<Types>::foo() , ...);
      |              ^~~
b.cpp:11:11: error: binary expression in operand of fold-expression
   11 |   (B<Types>::foo() , ...);
      |    ~~~~~~~^~~~~~~~
b.cpp:11:11: error: operand of fold expression has no unexpanded parameter packs
Comment 1 Marek Polacek 2020-04-18 17:20:37 UTC
Confirmed.  Doesn't seem like a regression.
Comment 2 Marek Polacek 2020-04-19 04:44:49 UTC
The difference stems from the fact that in this test:

template<typename>
struct B { };

template<typename... Types>
struct A : public B<Types>... {
    using B<Types>::B...; // #1
    using B<Types>::operator=...; // #2
};

int main() {}

when parsing B<Types> in #2 cp_parser_lookup_name finds #1, which is a dependent USING_DECL.  strip_using_decl doesn't do anything with such a USING_DECL, so we think that we haven't found a template name.
Comment 3 Marek Polacek 2020-04-19 15:09:15 UTC
Potential fix:

--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -16982,6 +16982,15 @@ cp_parser_template_name (cp_parser* parser,
 
   decl = strip_using_decl (decl);
 
+  if (TREE_CODE (decl) == USING_DECL
+      && TREE_CODE (USING_DECL_SCOPE (decl)) == TYPE_PACK_EXPANSION)
+    {
+      tree t = PACK_EXPANSION_PATTERN (USING_DECL_SCOPE (decl));
+      t = get_template_info (t);
+      if (t)
+   decl = TI_TEMPLATE (t);
+    }
+
   /* If DECL is a template, then the name was a template-name.  */
   if (TREE_CODE (decl) == TEMPLATE_DECL)
     {
Comment 4 Patrick Palka 2021-10-18 18:38:49 UTC
This looks fixed in GCC 11/12, ever since r11-6942
Comment 5 Andrew Pinski 2021-12-09 05:52:35 UTC
Dup of bug 80417.

*** This bug has been marked as a duplicate of bug 80417 ***