这是一种新的C++ 11评论风格吗?

Con*_*tor 12 c++ gcc comments g++ c++11

虽然我试图理解为什么代码int(*)();编译好用g ++编译我发现更奇怪的事情:

int main()
{
    int(*){} Is it C++11 or any other language?
}
Run Code Online (Sandbox Code Playgroud)

这段代码用g ++ 4.8.1编译得很好,参见live example(flags :)-std=c++11 -pedantic-errors.clang 3.4vc ++ 2013都没有编译它.

它是一种新的C++ 11样式的注释,只有g ++支持吗?还是编译错误?


以下是我发现的关于这种"评论"风格的内容:

  1. 注释的通常结构(可以省略的部分括在括号中[ ... ]):

    int // or another valid C++ type
    (*) // or another sequence of '*' and/or '&' characters with nonzero length
    {"[Comment header]"}
    [Comment body]
    {[Comment footnote]}
    
    Run Code Online (Sandbox Code Playgroud)
  2. 而不是使用脚注终止符号;可以使用:int(*){} Comment ;.

  3. 如果注释是块中的最后一个构造,{ ... }则可以省略终止符号和脚注:{ int(*){} Comment }.
  4. 允许的字符是以下列表中的数字,英文字母和字符:- + * / % & | ^ ~ = . , : ! ? $ ( ) [ ] < >.
  5. 注释正文或脚注中不允许使用以下字符:; { } # @.
  6. 注释正文或脚注中允许使用字符文字'...'和字符串文字"...",但符号'和符号"本身不能单独使用.
  7. 通常的C++注释// .../* ... */在新的"注释"中正常工作.预处理器指令,宏,有向图和三字图也可以正常工作(实例):

    #define TerminatingSymbol ;
    
        int(*) ??< %> // a pair of trigraph and digraph
        "This is a string" // string literal
    #if 1
        Comment
    #endif
        TerminatingSymbol
        std::cout << "Hello, ";
        int(*){} /* Character literal: */ 'c' <% ??>
        std::cout << "world!" << std::endl;
    
    Run Code Online (Sandbox Code Playgroud)
  8. 我无法理解浮点文字在这些"评论"中是如何工作的.


以下代码示例说明了新"注释"的功能:

#include <iostream>

int main()
{
    void(*){} do not try this float; // simple C++ keywords are allowed, of course
    std::cout << "1";
    int(&){"Allowed characters"}
    - + * / % & | ^ ~ = . , : ! ? $ ( ) [ ] < > ; // ';' itself is not allowed
    std::cout << "2";
    char(************************************)
    {"William Blake wrote:"}
    Tyger! Tyger! burning bright
    In the forests of the night,
    What immortal hand or eye
    Could frame thy fearful symmetry?
    {"The Tyger", 1794}
    std::cout << "3";
    float(*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*)
    {"Some formulas"}
    2 x 2 = 4
    pi ~= 3.145926 ...
    E = m * c ^ 2
    a ^ n + b ^ n != c ^ n, n > 2
    {42}
    std::cout << "4";
    unsigned(*(*(*(*(*(*(*(*(*(*())))))))))){}
    It is a last comment
}
Run Code Online (Sandbox Code Playgroud)