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

Aaron Ballman via All-commits all-commits at lists.llvm.org
Fri Aug 1 00:06:51 PDT 2025


  Branch: refs/heads/release/21.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 3b53c84e338bfb870f49e6a520725d86ff40c375
      https://github.com/llvm/llvm-project/commit/3b53c84e338bfb870f49e6a520725d86ff40c375
  Author: Aaron Ballman <aaron at aaronballman.com>
  Date:   2025-08-01 (Fri, 01 Aug 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

(cherry picked from commit 315e2e28b13285a352d409b739ba31fb453d661b)



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