llvm / llvm/llvm-project

clang++ -fsanitize=type reports type-aliasing-violation with const string and std ranges

Open
#218,496 0 comments 0 reactions 0 assignees View on GitHub
compiler-rt:tysan needs-reduction
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

``` c++
#include
#include

int main()
{
const std::string x[] = {"a", "b"};
x | std::views::join_with(std::string(", ")) | std::ranges::to();
}
```
```
clang++ --gcc-toolchain=/opt/gcc-15 -std=c++26 -fsanitize=type a.cpp && ./a.out
```
```
==127952==ERROR: TypeSanitizer: type-aliasing-violation on address 0x7fffc56b33b0 (pc 0x5c2f5cbcabac bp 0x7fffc56b32e0 sp 0x7fffc56b3268 tid 127952)
READ of size 8 at 0x7fffc56b33b0 with type p1 omnipotent char (in __gnu_cxx::__normal_iterator, std::allocator > > at offset 0) accesses an existing object of type p1 omnipotent char (in __gnu_cxx::__normal_iterator, std::allocator > > at offset 0)
```
Error disappears when `const` is removed.

`Ubuntu clang version 23.0.0 (++20260705082034+3be67c72f5d5-1~exp1~20260705202044.1706)`
gcc version 15.2.0 (GCC)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided C++26 example with clang++ and -fsanitize=type, comparing the const and non-const cases. Trace the TypeSanitizer report through the std::ranges expression; done means the const case no longer reports a type-aliasing violation and the regression is covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.