Author: rsmith Date: Thu Dec 21 14:26:47 2017 New Revision: 321318 URL: http://llvm.org/viewvc/llvm-project?rev=321318&view=rev Log: Suppress "redundant parens" warning for "A (::B())".
This is a slightly odd construct (it's more common to see "A (::B)()") but can happen in friend declarations, and the parens are not redundant as they prevent the :: binding to the left. Modified: cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/Parser/cxx-decl.cpp cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=321318&r1=321317&r2=321318&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Dec 21 14:26:47 2017 @@ -3165,7 +3165,12 @@ static void warnAboutRedundantParens(Sem // In a new-type-id, function chunks require parentheses. if (D.getContext() == Declarator::CXXNewContext) return; - LLVM_FALLTHROUGH; + // FIXME: "A(f())" deserves a vexing-parse warning, not just a + // redundant-parens warning, but we don't know whether the function + // chunk was syntactically valid as an expression here. + CouldBeTemporaryObject = false; + continue; + case DeclaratorChunk::BlockPointer: case DeclaratorChunk::MemberPointer: case DeclaratorChunk::Pipe: Modified: cfe/trunk/test/Parser/cxx-decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-decl.cpp?rev=321318&r1=321317&r2=321318&view=diff ============================================================================== --- cfe/trunk/test/Parser/cxx-decl.cpp (original) +++ cfe/trunk/test/Parser/cxx-decl.cpp Thu Dec 21 14:26:47 2017 @@ -282,6 +282,22 @@ namespace NNS { } } +inline namespace ParensAroundFriend { // expected-error 0-1{{C++11}} + struct A {}; + struct B { + static A C(); + }; + namespace X { + struct B {}; + struct D { + // No warning here: while this could be written as + // friend (::B::C)(); + // we do need parentheses *somewhere* here. + friend A (::B::C()); + }; + } +} + // PR8380 extern "" // expected-error {{unknown linkage language}} test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} Modified: cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp?rev=321318&r1=321317&r2=321318&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp (original) +++ cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp Thu Dec 21 14:26:47 2017 @@ -125,3 +125,20 @@ void fizbin() { baz b3; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}} } } + +namespace TemporaryFromFunctionCall { + struct A { + A(int); + }; + int f(); + int g(int); + namespace N { + void x() { + // FIXME: For the first and second of these (but not the third), we + // should produce a vexing-parse warning. + A(f()); + A(g(int())); + A(g(int)); + } + } +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits