久久久久久久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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 欧美一级片在线 | 日韩中文字幕在线不卡 | 69堂永久69tangcom | 玖草资源| 亚洲狠狠丁香婷婷综合久久久 | 97成人在线 | 免费观看av网站 | 亚洲精品免费在线观看 | 国产精品欧美日韩 | 午夜理伦三级理论三级在线观看 | 中文字幕在线一区 | 国产三级在线观看播放 | 99re6在线视频精品免费 | 国产一区精品 | 99精品欧美一区二区三区综合在线 | 亚洲男人天堂网 | 国产精品美女久久久久久免费 | 久久免费国产 | 美女视频一区 | 欧美日韩在线精品 | 韩国精品一区 | 亚洲福利 | 亚洲综合一区二区三区 | 在线观看国产wwwa级羞羞视频 | 伊人久久综合影院 | 不卡在线视频 | 一区中文字幕 | 精品乱码一区二区三四区 | 久久精品91久久久久久再现 | 国产精品色哟哟网站 | 亚洲国产成人精品久久久国产成人一区 | 欧美日韩电影一区 | 狠狠综合久久av一区二区小说 | 二区不卡 | 中文字幕一区在线观看视频 | 欧美一级二级在线观看 | 亚洲欧美日韩网站 | 精品一区久久 | 毛片视频网址 | 欧美日韩国产一区二区三区 | 久久国产视频网站 |