diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 14:41:26 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 18:26:25 +0100 |
commit | f213092d5a0b784df1b12ae62b7c5dcfb7d27280 (patch) | |
tree | a943252920f6420ffa16773c62e11cc89cce893c /compilerplugins | |
parent | 4655052a5c0b80a1d2f891849245215341a5218e (diff) |
loplugin:external: Extend comment about the perils of moving a function
...into an unnamed namespace. (And make it into a "leading comment" that
precedes the code it appeartains to. It had orignally been meant as a "trailing
comment" that follows the code it appeartains to, and had been idented further
to indicate that, but clang-format unhelpfully breaks such indentation of
trailing comments that need to be preceded by a line break due to line length
limitations.)
Change-Id: I6a71a6b8e11ba641acfb542142fe14b4b6445f51
Reviewed-on: https://gerrit.libreoffice.org/82792
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/external.cxx | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/compilerplugins/clang/external.cxx b/compilerplugins/clang/external.cxx index 442d174bd15b..3248df5db078 100644 --- a/compilerplugins/clang/external.cxx +++ b/compilerplugins/clang/external.cxx @@ -282,9 +282,38 @@ private: canStatic = isa<FunctionDecl>(decl) || isa<VarDecl>(decl) || isa<FunctionTemplateDecl>(decl) || isa<VarTemplateDecl>(decl); } + // In general, moving functions into an unnamed namespace can: break ADL like in + // + // struct S1 { int f() { return 1; } }; + // int f(S1 s) { return s.f(); } + // namespace N { + // struct S2: S1 { int f() { return 0; } }; + // int f(S2 s) { return s.f(); } // [*] + // } + // int main() { return f(N::S2()); } + // + // changing from returning 0 to returning 1 when [*] is moved into an unnamed namespace; can + // conflict with function declarations in the moved function like in + // + // int f(int) { return 0; } + // namespace { int f(int) { return 1; } } + // int g() { // [*] + // int f(int); + // return f(0); + // } + // int main() { return g(); } + // + // changing from returning 0 to returning 1 when [*] is moved into an unnamed namespace; and + // can conflict with overload resolution in general like in + // + // int f(int) { return 0; } + // namespace { int f(...) { return 1; } } + // int g() { return f(0); } // [*] + // int main() { return g(); } + // + // changing from returning 0 to returning 1 when [*] is moved into an unnamed namespace: auto const canUnnamed = compiler.getLangOpts().CPlusPlus && !(isa<FunctionDecl>(decl) || isa<FunctionTemplateDecl>(decl)); - // in general, moving functions into an unnamed namespace can break ADL assert(canStatic || canUnnamed); report( DiagnosticsEngine::Warning, |