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

2024-12-19


2969. Scopes in the function-try-block of a constructor

Section: 6.4  [basic.scope]     Status: open     Submitter: Richard Smith     Date: 2024-12-09

Per the specification, the block scope for a function-try-block does not include the ctor-initializer. Consider the following implementation divergence:

  struct A {
    A() try : p((struct B*)nullptr) {
      B *q;
      struct B {};
      B *r = q;       // EDG, GCC, MSVC: error: cannot convert, two different Bs
    } catch (...) {
      B *q;           // GCC: B not in scope here.
    }
   void *p;
  };

  struct C {
    C(int B) try : p((struct B*)0) {      // GCC: error: shadows parameter; MSVC: error: redefinition of B
    } catch (...) { }
    void *p;
  };

There is also implementation divergence regarding the scope of the ctor-initializer if no function-try-blocks are involved.