0

The following code does not compile (GCC, clang):

struct outer {
    struct inner {
        int i = 1;
        int j = 2;
    };
    void foo (const 
        inner& param = 
        inner{}) const {}
};

int main() {
    outer{}.foo();
}

However, adding a default constructor (with implementation) to inner solves the issue. Moving out inner to the namespace scope also helps.

What's the problem here? I'd appreciate references to the standard.

Igor R.
  • 14,716
  • 2
  • 49
  • 83
  • Are you sure that you build in C++17 mode? In C++11 structures with inline member initializations were *not* aggregates. This was removed in C++14. See e.g. [this aggregate iniitalization reference](https://en.cppreference.com/w/cpp/language/aggregate_initialization) for details. Or perhaps it's a bug in the compilers? Have you tried with e.g. MSVC++ (the [compiler explorer](https://godbolt.org/) is good for this)? – Some programmer dude Sep 26 '19 at 10:41
  • 1
    And *what* error are you getting? Please include the exact, complete and full error output in the question. – Some programmer dude Sep 26 '19 at 10:45
  • @Some programmer dude I believe sscce is enough ;). And thanks for the pointer to the duplicate, couldn't find it – Igor R. Sep 26 '19 at 12:23
  • 1
    @IgorR. It's me who flagged duplicate. – Language Lawyer Sep 26 '19 at 13:12

0 Answers0