3

The void() construction can be used to "create a value of the type void" (strange but true). But the C++11+ initialization syntax with curly braces doesn't work in such case:

int f_int_parenthesis()
{
    return int();  // OK
}

int f_int_braces()
{
    return int{};  // OK
}

void f_void_parenthesis()
{
    return void(); // OK
}

void f_void_braces()
{
    return void{}; // error
}

The code compilability is checked with g++ 7.2.0 and clang++ 3.8.0 (compilation flags are -std=c++14 -Wall -Wextra -Werror -pedantic-errors -O0).

Why is it so? Is it a standard-compliant behavior?

Constructor
  • 7,273
  • 2
  • 24
  • 66

0 Answers0