簡體   English   中英

使用非類型模板參數專門化模板模板參數

[英]Specialize template template parameter with a non-type template parameter

我正在嘗試對類模板進行部分特化,其中一個模板參數是包含單個非類型參數的模板模板參數。 例如:

template <
    class T, 
    template <class Result, Result> class BinaryOperation
>
struct Foo;

template <
    template <class Result, Result> class BinaryOperation
>
struct Foo<
    int,
    BinaryOperation
>
{ };

這段代碼使用 GCC-4.9.2 編譯得很好。

但是,使用 Clang-4.0,我收到一條神秘的錯誤消息:

$ clang++-4.0 test.cpp -o test -std=c++14 -stdlib=libc++ 
test.cpp:18:3: error: template template argument has different template parameters than its corresponding template template
      parameter
                BinaryOperation
                ^
test.cpp:14:33: note: template non-type parameter has a different type 'Result' in template argument
                template <class Result, Result> class BinaryOperation
                                              ^
test.cpp:9:33: note: previous non-type template parameter with type 'Result' is here
                template <class Result, Result> class BinaryOperation

我一直在谷歌上搜索這條錯誤消息,但我很不清楚。 似乎是說當Result作為模板參數出現時,與作為專業化列表的參數之一出現時,以某種方式被認為是不同的類型。

它適用於 GCC-4.9.2,所以我不知道這是否是 Clang 4 的問題,或者 GCC-4.9.2 是否允許它不應該的東西。

那么為什么 Clang-4 會報告這個編譯器錯誤呢?

在 Clang bugzilla 上報告了一個錯誤,標題為:別名模板產生看似虛假的“模板模板參數具有不同的模板參數”錯誤

這個錯誤可以在 Clang 4 中使用編譯器選項-frelaxed-template-template-args

在這里查看演示

這已在更高版本的 Clang 中得到修復(從 5.0.0 開始)。

暫無
暫無

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

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