Skip to content

clang::Interpreter cannot get the address of a static const member #146956

@jeaye

Description

@jeaye

This is easily reproducible via clang-repl, shown below, but the same issue exists for programmatic clang::Interpreter usage. @vgvassilev for vis.

# Unable to take the address of a static const member.
❯ clang-repl
clang-repl> struct foo{ static int const bar{ 5 }; };
clang-repl> int const *p{ &foo::bar };
clang-repl> #include <cstdio>
clang-repl> printf("%d\n", *p);
JIT session error: Symbols not found: [ _ZN3foo3barE ]
Segmentation fault (core dumped)

# Getting its value works fine.
❯ clang-repl
clang-repl> struct foo{ static int const bar{ 5 }; };
clang-repl> int const i{ foo::bar };
clang-repl> #include <cstdio>
clang-repl> printf("%d\n", i);
5

❯ clang-repl --version
LLVM (http://llvm.org/):
  LLVM version 19.1.7
  Optimized build.

I have verified this bug exists on versions:

  • 19.1.7
  • 20.1.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions