Question Details

No question body available.

Tags

c++ visual-studio templates function-declaration default-arguments

Answers (1)

Accepted Answer Available
Accepted Answer
January 15, 2026 Score: 7 Rep: 313,249 Quality: Expert Completeness: 50%

It is a bug of the MS C++ compiler. For example within the C++23 Standard in the section "9.3.4.7 Default arguments", p.#9 there is present the following example

9 A default argument is evaluated each time the function is called with no argument for the corresponding parameter. A parameter shall not appear as a potentially-evaluated expression in a default argument.

  int h(int a, int b = sizeof(a)); // OK, unevaluated operand (7.2.3)  

Someday I tried the following simple function declaration in MS C++

 void f( int x, size_t n = sizeof x );

and I got an error saying that using a local variable as a default argument is not allowed.