[all-commits] [llvm/llvm-project] 83a944: [Sema] Skip expansion statements when determing lo...

Oliver Hunt via All-commits all-commits at lists.llvm.org
Fri Jul 24 14:02:31 PDT 2026


  Branch: refs/heads/users/ojhunt/oliver-vs-expansion-statements
  Home:   https://github.com/llvm/llvm-project
  Commit: 83a944a6f7263b5402ef8161a8f638ec2f41ac6c
      https://github.com/llvm/llvm-project/commit/83a944a6f7263b5402ef8161a8f638ec2f41ac6c
  Author: Oliver Hunt <oliver at apple.com>
  Date:   2026-07-24 (Fri, 24 Jul 2026)

  Changed paths:
    M clang/lib/AST/Decl.cpp
    M clang/lib/Sema/SemaDecl.cpp
    A clang/test/SemaCXX/Inputs/initializer-list.h
    M clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
    A clang/test/SemaCXX/expansion-statements-local-extern-decls.cpp

  Log Message:
  -----------
  [Sema] Skip expansion statements when determing local extern context (#210512)

This bug showed up as a failed assertion that was asserting that if
not in a function or method context we should be in the global/file
context.

The root cause is that when determining the linkage context for a
decl we were failing to account for the existence of expansion
contexts. Ignoring the assertion failure, the functional effect of
this is that we would fail to detect incorrect local extern
declarations inside expansion contexts. The fix here is to make
sure that we use `getEnclosingNonExpansionStatementContext()` to
find the true DeclContext for the current scope.

The initial report only identified local extern function declarations
but the same bug occurred with extern var decls, but the path did
not lead to an assertion firing, just incorrect behaviour.

Thanks to Sirraide for explaining why this was going wrong, and
confirming this was the correct fix.

For testing I pulled the std::initializer_list declaration from
cxx0x-initializer-stdinitializerlist.cpp into a separate header.

Also fixes #211912



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