https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68170

            Bug ID: 68170
           Summary: Declaring friend template class template in C++1z
                    produces error: specialization of ‘template<class T>
                    class A’ must appear at namespace
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mohammad.nabil.h at gmail dot com
  Target Milestone: ---

Created attachment 36627
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36627&action=edit
Preprocessed file

I am using gcc-6-20151025 snapshot with -std=c++1z and I got an error deep in
boost's source code. I isolated the error and this is a minimal example:

    template< typename T >
    class A
    {
    };

    template<>
    class A< void >
    {
            template< typename X >
            friend class A;
    };

It compiles fine with -std=c++14, but generates the following error for
-std=c++1z:

    error: specialization of ‘template<class T> class A’ must appear at
namespace scope
      friend class A;
                   ^

I traced the error in the sources and it appears the behavior diverges in the
newly-introduced function `maybe_new_partial_specialization' in pt.c. In
particular in a condition that only activates when Concepts TS is active
(pt.c:867).

I was told that concepts should not affect pre-concepts valid programs, so this
should be a bug.

The command line is: 
PATH=~/src/gcc-6-pristine/stage1-gcc ~/src/gcc-6-pristine/stage1-gcc/xg++ -v
-save-temps -std=c++1z example.C

Its output is:
-----8<-----
Using built-in specs.
COLLECT_GCC=/home/malaggan/src/gcc-6-pristine/stage1-gcc/xg++
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-6-20151025-pristine/configure
--prefix=/home/malaggan/opt --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 6.0.0 20151025 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++1z' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 cc1plus -E -quiet -v -iprefix
/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/x86_64-pc-linux-gnu/6.0.0/
-D_GNU_SOURCE meemo.C -mtune=generic -march=x86-64 -std=c++1z -fpch-preprocess
-o meemo.ii
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../include/c++/6.0.0"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../include/c++/6.0.0/x86_64-pc-linux-gnu"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../include/c++/6.0.0/backward"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/x86_64-pc-linux-gnu/6.0.0/include"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/x86_64-pc-linux-gnu/6.0.0/include-fixed"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../x86_64-pc-linux-gnu/include"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../include/c++/6.0.0"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../include/c++/6.0.0/x86_64-pc-linux-gnu"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../include/c++/6.0.0/backward"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.0.0/include"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/../../include"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.0.0/include-fixed"
ignoring nonexistent directory
"/home/malaggan/src/gcc-6-pristine/stage1-gcc/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++1z' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 cc1plus -fpreprocessed meemo.ii -quiet -dumpbase meemo.C -mtune=generic
-march=x86-64 -auxbase meemo -std=c++1z -version -o meemo.s
GNU C++14 (GCC) version 6.0.0 20151025 (experimental) (x86_64-pc-linux-gnu)
        compiled by GNU C version 5.2.0, GMP version 6.0.0, MPFR version
3.1.3-p4, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C++14 (GCC) version 6.0.0 20151025 (experimental) (x86_64-pc-linux-gnu)
        compiled by GNU C version 5.2.0, GMP version 6.0.0, MPFR version
3.1.3-p4, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 60213cfad0705f5376fd5cf5a4075346
meemo.C:13:15: error: specialization of ‘template<class T> class A’ must appear
at namespace scope
  friend class A;
-----8<-----

Thank you.

Reply via email to