Skip to content

Commit

Permalink
Merge pull request #5190 from AndrejMitrovic/fix-15186
Browse files Browse the repository at this point in the history
Issue 15186 - Emit better diagnostic for C++ member lookup operators
  • Loading branch information
andralex committed Oct 11, 2015
2 parents 65b079f + 4a7fbdc commit c5a0636
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -4438,6 +4438,16 @@ public:
Token* t = peek(&token);
if (t.value == TOKcolon)
{
Token* nt = peek(t);
if (nt.value == TOKcolon)
{
// skip ident::
nextToken();
nextToken();
nextToken();
error("use '.' for member lookup, not '::'");
break;
}
// It's a label
Identifier ident = token.ident;
nextToken();
Expand Down Expand Up @@ -6485,6 +6495,18 @@ public:
{
case TOKidentifier:
{
Token* t1 = peek(&token);
Token* t2 = peek(t1);
if (t1.value == TOKmin && t2.value == TOKgt)
{
// skip ident->
nextToken();
nextToken();
nextToken();
error("use '.' for member lookup, not '->'");
goto Lerr;
}

if (peekNext() == TOKgoesto)
goto case_delegate;
id = token.ident;
Expand Down
16 changes: 16 additions & 0 deletions test/fail_compilation/diag15186.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag15186.d(14): Error: use '.' for member lookup, not '::'
fail_compilation/diag15186.d(15): Error: use '.' for member lookup, not '->'
---
*/

void main()
{
struct S { static int x; int y; }
S* s;

S::x = 1;
s->y = 2;
}

0 comments on commit c5a0636

Please sign in to comment.