compilerplugins/clang/external.cxx | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
New commits: commit f213092d5a0b784df1b12ae62b7c5dcfb7d27280 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Fri Nov 15 14:41:26 2019 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Fri Nov 15 18:26:25 2019 +0100 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 <sberg...@redhat.com> 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, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits