久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

我對 is_complete 類型特征的實現是否暴露了編譯器

Is there a compiler bug exposed by my implementation of an is_complete type trait?(我對 is_complete 類型特征的實現是否暴露了編譯器錯誤?)
本文介紹了我對 is_complete 類型特征的實現是否暴露了編譯器錯誤?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我寫了這個 C++11 trait 模板來檢查一個類型是否完整:

I wrote this C++11 trait template to check whether a type is complete:

template <typename...>
using void_t = void;

template <typename T, typename = void>
struct is_complete : std::false_type
{};

template <typename T>
struct is_complete<T, void_t<decltype(sizeof(T))>> : std::true_type
{};

并像這樣測試:

struct Complete {};

int main()
{
    std::cout << is_complete<Complete>::value
              << is_complete<class Incomplete>::value
              << '
';
}

我希望測試程序打印10,這就是我用clang 3.4 編譯它時得到的輸出.但是,當使用 gcc 4.9 編譯時,它會打印 11 —— 錯誤地將 class Incomplete 識別為完整.

I expected the test program to print 10, and that is the output I get when I compile it with clang 3.4. However, when compiled with gcc 4.9, it prints 11 instead -- mistakenly identifying class Incomplete as complete.

我不確定我的代碼是否正確,但在我看來,即使它是錯誤的,它在兩個編譯器上的行為也應該相同.

I don't know for sure if my code is correct, but it seems to me that even if it's wrong, it should behave the same on both compilers.

問題 1:我的代碼正確嗎?
問題 2:我是否在其中一個編譯器中發現了錯誤?

Question 1: Is my code correct?
Question 2: Have I found a bug in one of the compilers?

我不是要求替換我的代碼.我在問 gcc 或 clang 中是否存在錯誤,以及這個特定的構造是否正確.

I'm not asking for a replacement for my code. I'm asking whether there is a bug in gcc or clang, and whether or not this particular construct is correct.

推薦答案

問題似乎出在 void_t 的定義上.定義為

The problem appears to be with the definition of void_t. Defining it as

template<typename... Ts>
struct make_void { typedef void type;};

template<typename... Ts>
using void_t = typename make_void<Ts...>::type;

而是在兩個編譯器上產生正確的結果(10)(Demo).

instead yields the correct result (10) on both compilers (Demo).

我相信這與 N3911,論文提出了 void_t 和 CWG 問題 1558.本質上,該標準不清楚別名模板特化中未使用的參數是否會導致替換失敗或被簡單地忽略.委員會 2014 年 11 月會議通過的 CWG 問題決議闡明了問題中 void_t 的較短定義應該有效,并且 GCC 5.0 實施了該決議.

I believe this is the same issue noted in section 2.3 of N3911, the paper proposing void_t, and CWG issue 1558. Essentially, the standard was unclear whether unused arguments in alias template specializations could result in substitution failure or are simply ignored. The resolution of the CWG issue, adopted at the Committee's November 2014 meeting, clarifies that the shorter definition of void_t in the question should work, and GCC 5.0 implements the resolution.

這篇關于我對 is_complete 類型特征的實現是否暴露了編譯器錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 亚洲自拍偷拍视频 | 日韩av三区 | 久久噜噜噜精品国产亚洲综合 | 中文在线一区 | 欧美中文字幕一区二区三区亚洲 | 老妇激情毛片免费 | 三级在线观看 | 久久精品亚洲精品 | 夜夜骑综合 | aaaaaaa片毛片免费观看 | 久久一区视频 | 欧美国产日韩在线观看 | 成人一区二 | 亚洲国产一区二区视频 | 91看片在线观看 | 嫩草视频网 | 亚洲视频在线观看一区二区三区 | 伊人精品在线 | 亚洲成人一区二区三区 | 午夜视频在线免费观看 | 美女福利视频网站 | 99精品免费久久久久久日本 | 国产精品中文字幕一区二区三区 | 中文字幕成人在线 | 波多野结衣一区二区三区 | 91久久久久久久 | 亚洲精品美女视频 | 亚洲精品电影在线观看 | 国产一区二区在线免费 | 二区欧美 | 亚洲aⅴ| 日本精品久久 | 欧美国产日韩在线 | 久久精品视频在线观看 | 欧美成人一级视频 | 日韩精品在线一区 | 欧美自拍第一页 | 色视频www在线播放国产人成 | 日日操夜夜操天天操 | 国产人成在线观看 | 在线观看日韩精品视频 |