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

            Bug ID: 94255
           Summary: template specialization in different namespace causes
                    crash
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vince.a.bridgers at gmail dot com
  Target Milestone: ---

I encountered this issue using gcc/g++ 6.2.0, then 8.2.0, the tried trunk that
I built on rhel7. g++ crashes when trying to compile code with template
specialization in different namespace. I know this is incorrect code, but I
wouldn't expect g++ to crash. For reference, clang 8.0.0 compiles this and
gives an error. 


----
Last git hash in log

commit 9def91e9f2a7051c9c146f16c1a10d1b25d33b47
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Mar 19 22:56:20 2020 +0100

---
Configure step for custom, trunk build ... 

../gcc/configure --enable-languages=c,c++ --disable-multilib
--prefix=<home>/gcc-install

----
$ g++ --version
g++ (GCC) 10.0.1 20200319 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

----
$ g++ gcc-test.cpp 
gcc-test.cpp:15:38: error: specialization of ‘template<class T, class EnablerT>
struct clang::DynTypedNode::BaseConverter’ in different namespace
[-fpermissive]
   15 |     template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
gcc-test.cpp:5:60: note:   from definition of ‘template<class T, class
EnablerT> struct clang::DynTypedNode::BaseConverter’
    5 |     template <typename T, typename EnablerT = void> struct
BaseConverter;
      |                                                           
^~~~~~~~~~~~~
g++: internal compiler error: Segmentation fault signal terminated program
cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

----
cat test.cpp  ... 

namespace clang {
  class DynTypedNode {
  private:
    template <typename T, typename EnablerT = void> struct BaseConverter;
    template <typename T> struct ValueConverter {};
  };
  namespace ast_type_traits {
    using DynTypedNode = ::clang::DynTypedNode;
  }; // end namespace ast_type_traits
}; // end namespace clang

namespace clang {
  namespace ast_type_traits {
    template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
  }; // end namespace ast_type_traits
}; // end namespace clang

int main(void) {
    return 0;
}

---
cat gcc-test.ii ...

# 1 "gcc-test.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "gcc-test.cpp"

namespace clang {
  class DynTypedNode {
  private:
    template <typename T, typename EnablerT = void> struct BaseConverter;
    template <typename T> struct ValueConverter {};
  };
  namespace ast_type_traits {
    using DynTypedNode = ::clang::DynTypedNode;
  };
};

namespace clang {
  namespace ast_type_traits {
    template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
  };
};

int main(void) {
    return 0;
}


----
$ clang --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /app/vbuild/RHEL7-x86_64/clang/8.0.0/bin


$ clang test.cpp 
gcc-test.cpp:15:38: error: class template specialization of 'BaseConverter' not
in class 'DynTypedNode' or an enclosing namespace
    template <> struct DynTypedNode::BaseConverter<int, void> : public
ValueConverter<int> {};
                                     ^
gcc-test.cpp:5:60: note: explicitly specialized declaration is here
    template <typename T, typename EnablerT = void> struct BaseConverter;
                                                           ^
1 error generated.

Reply via email to