https://bugs.llvm.org/show_bug.cgi?id=37767

            Bug ID: 37767
           Summary: LLVM_NODISCARD does not work in for loops.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Support Libraries
          Assignee: unassignedb...@nondot.org
          Reporter: gchate...@google.com
                CC: llvm-bugs@lists.llvm.org

See the following snippe (https://godbolt.org/g/DxoBaC)

> #include "llvm/Support/Error.h"
> 
> struct A {
>     llvm::Error foo() const;
> };
> 
> void bar(llvm::ArrayRef<A> As) {
>     for(const auto& A : As)
>         A.foo(); // No warning.
> }
> 
> void baz(llvm::ArrayRef<A> As) {
>     As.front().foo(); // Warning.
> }

llvm::Error is marked LLVM_NODISCARD and should generate a warning if not
consumed.

`baz` generates a warning with clang but `bar` does not.

When using gcc, no warning is generated at all.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to