cling/test/CodeUnloading/unnamedns.h
Javier Lopez-Gomez 2ec73dd62a DeclUnloader: reset the anonymous namespace in the enclosing DC
From SemaDeclCXX.cpp:
```
C++ [namespace.unnamed]p1.  An unnamed-namespace-definition behaves as if it
were replaced by
     namespace unique { /* empty body */ }
     using namespace unique;
     namespace unique { namespace-body }
where all occurrences of 'unique' in a translation unit are replaced by the same
identifier and this identifier differs from all other identifiers in the entire
program.
```

Thus, the first declaration of an unnamed namespace creates an implicit
UsingDirectiveDecl that makes the names available in the parent DC.

If we are reverting such first declaration, make sure we reset the anonymous
namespace for the parent DeclContext so that the implicit UsingDirectiveDecl
is created again when parsing the next anonymous namespace.

Fixes issue #7483.
2022-03-01 12:59:03 +01:00

8 lines
73 B
C

namespace {
int h = 12;
}
void unnamedns() {
printf("%d\n", ++h);
}