[PATCH] D80977: Diagnose cases where the name of a class member is used within a class definition before the member name is declared.

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 19 19:32:14 PDT 2020


efriedma added a comment.

(Partial review; I'll continue reviewing later.)



================
Comment at: clang/lib/Sema/SemaDecl.cpp:1543
+    // in class 'C', where we look up 'f' to determine if we're declaring a
+    // constructor.
+  } else if (D->isInIdentifierNamespace(Lookup.FirstIDNS)) {
----------------
Not really about this patch, but take given the following example:

```
typedef int f;
class C { C (f)(); };
```

It looks like every compiler somehow parses this as an invalid constructor declaration.  As far as I can tell, it doesn't conform to the grammar for a constructor, though: parentheses aren't allowed after the parameter-declaration-clause. So it should declare a member function f, whether or not `f` is a type.  Maybe I'm missing something, though.

It doesn't matter for this patch, of course, because you can also write `C(f());`, which actually depends on whether `f` is a type.


================
Comment at: clang/test/CXX/basic/basic.scope/basic.scope.class/p2.cpp:154
+
+  static int a = unique_member_function_name(); // expected-error {{undeclared identifier}}
+  static int unique_member_function_name();
----------------
I'm seeing a test failure here with this patch applied.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80977/new/

https://reviews.llvm.org/D80977





More information about the cfe-commits mailing list