<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/79668>79668</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Nested type lookup is unstable/not comprehensive
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            clayborg
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dwblaikie
      </td>
    </tr>
</table>

<pre>
    Lookup of nested types was a bit buggy previously (#53904) and that was possibly fixed by #77029 but looks like this might've made things differently buggy/problematic.

Essentially, it's not possible to rely on a single definition a type to contain all the nested types. This is partly because the compiler doesn't produce them into the DWARF. Since it's not possible sometimes to provide the definitions (in the below example, the definition is only available in one translation units, but not another) - but even the declaration is not emitted by the compiler in the translation units where it is not required, to save space. But worst case, even the declaration wouldn't be available - as in the case of nested templates (`struct t1 { template<typename T> struct t2 { ... } };` - in this case, even the declaration of `t1::t2<int>`, for instance, wouldn't be available in every copy of `t1`).

Looks like the debugger would need to search for nested types in all copies of a type available in the DWARF.

Consider the following example:

`test.h`:
```
struct outer {
  enum enumeration : int;
};
void f1();
```
`test.cpp`:
```
#include "test.h"
int main() {
 outer o;
  f1();
}
```
`test2.cpp`:
```
#include "test.h"
enum outer::enumeration : int {
  enumerator
};
void f1() {
  outer::enumeration e;
}
```
```
$ clang++-tot -g test.cpp test2.cpp && lldb ./a.out -b -o "p outer::enumeration::enumerator"
(lldb) target create "./a.out"
Current executable set to '/usr/local/google/home/blaikie/dev/scratch/a.out' (x86_64).
(lldb) p outer::enumeration::enumerator
error: <user expression 0>:1:8: no member named 'enumeration' in 'outer'
    1 | outer::enumeration::enumerator
 | ~~~~~~~^
$ clang++-tot -g test2.cpp test.cpp && lldb ./a.out -b -o "p outer::enumeration::enumerator"
(lldb) target create "./a.out"
Current executable set to '/usr/local/google/home/blaikie/dev/scratch/a.out' (x86_64).
(lldb) p outer::enumeration::enumerator
(outer::enumeration) enumerator
```
And gdb gets this right in any order (and without the excess enumeration scoping, but that's a separate bug):
```
$ clang++-tot -g test2.cpp test.cpp && gdb -batch -ex "p outer::enumerator" -args ./a.out
Unable to determine compiler version.
Skipping loading of libstdc++ pretty-printers for now.
Loading libc++ pretty-printers.
Non-google3 binary detected.
$1 = outer::enumerator
$ clang++-tot -g test.cpp test2.cpp&& gdb -batch -ex "p outer::enumerator" -args ./a.out
Unable to determine compiler version.
Skipping loading of libstdc++ pretty-printers for now.
Loading libc++ pretty-printers.
Non-google3 binary detected.
$1 = outer::enumerator
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV0tz4zYM_jX0BWOPTDmWffDBefi0s4fudnrsUBIssaFIlYTs6NLf3gElv7rx7mZ63UxixSQIfPjwIKRC0JVF3IiHRyFlYVSfO18JKcXD80R1VDu_KY-5UfpV4yR3Zb_55Nxr14Lbg8VAWAL1LQY4qgAKck2Qd1XVQ-vxoF0XTA9CroRMH9J1shByDcqWQLWieKR1Iejc9LDXb1hCztJpliVyDXlHYJx7DWD0KwLVOkCjq5qEzA4IjSrjoq0ClHq_R4-WTD-YF3LXepcbbBTpYiaSZ5Fsh8-XENCSVsb0Qj6BZnUBrKMTFgRy4NH04CwoCNpWBqHEvbaadFxjl1mqcJaUtqCMAarxhpEZfGXEOkCrfASGheoCRsHCNa026KF0GKyQGUHrXdkVcbsBbclFwec_tr_tZvBF2wLfxRpcg6QbDIyn9e6gy8HEBXDgCGgbV3M07gj4pprWIPt_K8pwnTU9qIPSRrEBbcFZBPLKBqOiUGc1BT7MIWI0yjqq0XN0p3ERD2hH1YVRXp10szA2mmiI9Q0VI8JvDMGxRs_OnxR4_LvTHssI30FQB4TQqgJn8NgRHJ0PBIUK0b93kRxdZ8qB9hyvfJ2CCiccrOA6y7FpjSKMZIplEsh3BQHNQWSP512RPnHwrWoQvor0BU5iMorNZjMQ2TP_ifRRLBOYDuZ0-D5gtwexTGgu0q1It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