This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


2367. Lambdas in default arguments vs the ODR

Section: 6.3  [basic.def.odr]     Status: NAD     Submitter: Richard Smith     Date: 2017-11-10

According to 6.3 [basic.def.odr] bullet 6.5,

However, this rule is insufficient to handle a case like:

  struct A {
    template<typename T> A(T);
  };
  void f(A a = []{});
  inline void g() {
    f();
  }

This should be an ODR violation, because the call to f() will invoke a different specialization of the constructor template in each translation unit, but it is not, because the rule says this example is equivalent to:

  inline void g() {
   f([]{});
  }

which is not an ODR violation, since the type of the closure object will be the same in every translation unit (9.2.8 [dcl.inline] paragraph 6) ..

Notes from the October, 2018 teleconference:

This will be addressed by work already underway to rework the relationship between lambdas and the ODR.

Rationale (February, 2021):

The resolution of issue 2300 makes clear that this example is an ODR violation.