Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 434ed26

Browse files
author
Kaelyn Uhrain
committed
In Parser::isCXXDeclarationSpecifier, consider a non-type identifier
followed by an identifier as declaration specificer (except for ObjC). This allows e.g. an out-of-line C++ member function definitions to be recognized as functions and not as variable declarations if the type name for the first parameter is not recognized as a type--say, when there is a function name shadowing an enum type name and the parameter is missing the "enum" keyword needed to distinguish the two. Note that returning TPResult::Error() instead of TPResult::True() appears to have the same end result, while TPResult::Ambiguous() results in a crash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155163 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0c5d0a8 commit 434ed26

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: lib/Parse/ParseTentative.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,12 @@ Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult) {
931931
// recurse to handle whatever we get.
932932
if (TryAnnotateTypeOrScopeToken())
933933
return TPResult::Error();
934-
if (Tok.is(tok::identifier))
935-
return TPResult::False();
934+
if (Tok.is(tok::identifier)) {
935+
const Token &Next = NextToken();
936+
bool NotObjC = !(getLangOpts().ObjC1 || getLangOpts().ObjC2);
937+
return (NotObjC && Next.is(tok::identifier)) ?
938+
TPResult::True() : TPResult::False();
939+
}
936940
return isCXXDeclarationSpecifier(BracedCastResult);
937941

938942
case tok::coloncolon: { // ::foo::bar

Diff for: test/FixIt/fixit.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,15 @@ template<template<typename> Foo, // expected-error {{template template parameter
204204
template<typename> typename Bar, // expected-error {{template template parameter requires 'class' after the parameter list}}
205205
template<typename> struct Baz> // expected-error {{template template parameter requires 'class' after the parameter list}}
206206
void func();
207+
208+
209+
namespace ShadowedTagType {
210+
class Foo {
211+
public:
212+
enum Bar { X, Y };
213+
void SetBar(Bar bar);
214+
Bar Bar();
215+
private:
216+
Bar bar_; // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}}
217+
};
218+
void Foo::SetBar(Bar bar) { bar_ = bar; } // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}}

0 commit comments

Comments
 (0)