Issue 182177
Summary Missing `-Wrange-loop-construct` when class is annotated with `[[clang::trivial_abi]]`
Labels clang:diagnostics, false-negative
Assignees
Reporter aaronpuchert
    Compile this with `-Wrange-loop-construct`:
```c++
struct [[clang::trivial_abi]] Ptr {
    Ptr();
    Ptr(const Ptr&);
    Ptr(Ptr&&) noexcept;
    Ptr& operator=(const Ptr&);
    Ptr& operator=(Ptr&&) noexcept;
    ~Ptr();

 int& operator*() const;
};

void f() {
    Ptr ptrs[1];
    for (const auto p : ptrs)
        *p = 0;
}
```
There is no warning. But there is one if we remove the `[[clang::trivial_abi]]` attribute:
```
<source>:14:21: warning: loop variable 'p' creates a copy from type 'const Ptr' [-Wrange-loop-construct]
   14 |     for (const auto p : ptrs)
      |                     ^
<source>:14:10: note: use reference type 'const Ptr &' to prevent copying
   14 |     for (const auto p : ptrs)
      |          ^~~~~~~~~~~~~~
      |                     &
```
I don't see why the warning should disappear. The attribute simply means that the class can be passed in registers, but this does not make the copy trivial.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to