-
Notifications
You must be signed in to change notification settings - Fork 13.5k
clang-repl doesn't execute top-level code located inside a namespace #73632
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
Comments
see compiler-research/xeus-clang-repl#72 for more detail on the motivation |
More detail: this is probably a bug, because |
Hi @p4vook, I am a little worried in allowing to execute statements on namespace level. However, it generally is consistent with the way C++ models static initialization. The example below prints extern "C" int printf(const char*,...);
int i1 = printf("i1\n");
namespace N {int i2 = printf("i2\n");}
int main() {
} I'd prefer to keep this as a patch and if this feature enables really variable redefinition in Jupyter cells with clang-repl we can pursue it. What do you think? cc: @AaronBallman |
Change the declaration context where we insert top-level statements to the current enclosing namespace context. Previously, top-level statement declarations were inserted directly into the translation unit. This is incorrect, as it leads to ignoring such statements located inside namespaces. Fixes: llvm#73632 Signed-off-by: Pavel Kalugin <[email protected]>
Oops, I'm sorry for missing your question earlier. Yes, I'm absolutely fine with it being in a separate patch, as this behavior could be controversial. Although it seems that the I'd be glad if someone with a deeper knowledge of the Clang AST could provide some insights. |
Consider the following piece of code:
Currently
clang-repl
does not execute the code insidens
.However, executing top-level code inside namespaces not only seems the logical thing to do, but it could also prove to be useful when implementing proper notebook integration: consider this example:
This code is, indeed, incorrect: C++ does not allow variable or function redefinition.
However, it could potentially be rewritten into working code using C++17 syntax for nested namespaces:
This does not require any messing with compiler internals, so should behave in a way that's more predictable.
The text was updated successfully, but these errors were encountered: