簡體   English   中英

這是部分 class 專業化錯誤還是 clang 或 gcc 中的錯誤?

[英]Is this partial class specialization buggy or is it a bug in clang or gcc?

template <class A>
struct Foo {
  template <class Bar>
  constexpr auto a_method();
};

template <class A>
template <class Bar>
constexpr auto Foo<A>::a_method() {
    return 42;
}

template <>
template <class Bar>
constexpr auto Foo<void>::a_method() {
    return 42;
}

GCC可以編譯這個。

但是 Clang不能 錯誤 output:

<source>:15:27: error: conflicting types for 'a_method'
constexpr auto Foo<void>::a_method() {
                          ^
<source>:4:18: note: previous declaration is here
  constexpr auto a_method();
                 ^
1 error generated.
Compiler returned: 1

僅當關鍵字auto用作上述代碼中 function 的返回類型時,這似乎是一個問題

例如,如果您不使用auto作為 function a_method返回類型,而是使用任何其他類型作為返回類型,則程序將編譯.

這似乎是 Clang 中的一個錯誤。

我注意到的另一件事是,如果您首先為 class 模板提供明確的特化,那么代碼將使用auto編譯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM