Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cling] Decls in an unnamed namespace cannot be looked up after a unload-load cycle #7483

Closed
Axel-Naumann opened this issue Mar 12, 2021 · 0 comments · Fixed by #9998
Closed

Comments

@Axel-Naumann
Copy link
Member

Describe the bug

A definition in an unnamed namespace cannot be redeclared by re-running the same code.

Expected behavior

A new declaration is provided; 13 is printed twice.

To Reproduce

// t.cxx
namespace {
  int h = 12;
}

void t() {
  printf("%d\n", ++h);
}
root [0] .x t.cxx
13
root [1] .x t.cxx
In file included from input_line_10:1:
t.cxx:6:20: error: use of undeclared identifier 'h'
  printf("%d\n", ++h);
                   ^

Setup

ROOT master Ubuntu

@jalopezg-git jalopezg-git changed the title Cannot redefine entities in unnamed namespace [cling] Decls in an unnamed namespace cannot be looked up after a unload-load cycle Feb 28, 2022
jalopezg-git added a commit to jalopezg-git/root that referenced this issue Feb 28, 2022
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 root-project#7483.
jalopezg-git added a commit to jalopezg-git/root that referenced this issue Feb 28, 2022
jalopezg-git added a commit to jalopezg-git/root that referenced this issue Feb 28, 2022
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 root-project#7483.
jalopezg-git added a commit to jalopezg-git/root that referenced this issue Feb 28, 2022
jalopezg-git added a commit to jalopezg-git/root that referenced this issue Feb 28, 2022
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 root-project#7483.
jalopezg-git added a commit that referenced this issue Mar 1, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants