[all-commits] [llvm/llvm-project] 315e2e: [C23] Handle type compatibility for enumerations b...

Aaron Ballman via All-commits all-commits at lists.llvm.org
Tue Jul 29 05:21:21 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 315e2e28b13285a352d409b739ba31fb453d661b
      https://github.com/llvm/llvm-project/commit/315e2e28b13285a352d409b739ba31fb453d661b
  Author: Aaron Ballman <aaron at aaronballman.com>
  Date:   2025-07-29 (Tue, 29 Jul 2025)

  Changed paths:
    M clang/lib/AST/ASTStructuralEquivalence.cpp
    M clang/test/C/C23/n3037.c

  Log Message:
  -----------
  [C23] Handle type compatibility for enumerations better (#150282)

An enumeration is compatible with its underlying type, which means that
code like the following should be accepted:

  struct A { int h; };
  void func() {
    extern struct A x;
    enum E : int { e };
    struct A { enum E h; };
    extern struct A x;
  }

because the structures are declared in different scopes, the two
declarations of 'x' are both compatible.

Note, the structural equivalence checker does not take scope into
account, but that is something the C standard requires. This means we
are accepting code we should be rejecting per the standard, like:

  void func() {
    struct A { int h; };
    extern struct A x;
    enum E : int { e };
    struct A { enum E h; };
    extern struct A x;
  }

Because the structures are declared in the same scope, the type
compatibility rule require the structures to use the same types, not
merely compatible ones.

Fixes #149965



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list