显式模板实例化定义的“显式默认定义”错误 (Clang VS GCC)

"definition of explicitly-defaulted" error with explicit template instantiation definition (Clang VS GCC)

提问人:Vittorio Romeo 提问时间:4/3/2023 更新时间:4/3/2023 访问量:180

问:

请考虑以下代码:

template <typename> struct S { S(); };
// extern template struct S<int>;
template <typename T> S<T>::S() = default;
template S<int>::S();

clang++愉快地接受这个代码。

g++投诉:

error: definition of explicitly-defaulted 'S< <template-parameter-1-1> >::S() 
       [with <template-parameter-1-1> = int]'
    3 | template <typename T> S<T>::S() = default;
      |                       ^~~~

取消注释修复编译(并且仍然很高兴)。extern templateg++clang++

g++ 拒绝代码是否正确?

C++ 模板 language-lawyer extern explicit-instantiation

评论

0赞 StoryTeller - Unslander Monica 4/3/2023
GCC 也乐于用大括号代替(就像 Clang 一样)。=default;
0赞 user17732522 4/3/2023
我看不出海湾合作委员会有理由拒绝它。
0赞 Brian Bi 4/3/2023
针对 GCC 提交错误?
0赞 Vittorio Romeo 4/3/2023
报告为:gcc.gnu.org/bugzilla/show_bug.cgi?id=109387

答: 暂无答案