[llvm-bugs] [Bug 25876] New: -Wliteral-conversion warns about implicit conversion changing 0.99 to false

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 17 15:45:45 PST 2015


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

            Bug ID: 25876
           Summary: -Wliteral-conversion warns about implicit conversion
                    changing 0.99 to false
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: gpakosz at pempek.net
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following program makes clang 3.7 emit a curious warning:
 ~ clang main.c                                                                
                                                                   
main.c:6:10: warning: implicit conversion from 'float' to 'bool' changes value
from 0.99 to false [-Wliteral-conversion]
  return 0.99f;
  ~~~~~~ ^~~~~
1 warning generated.

---

#include <stdio.h>
#include <stdbool.h>

bool f()
{
  return 1.99f;
}

int main(int argc, char* argv[])
{
  if (f())
  {
    printf("yep!\n");
  }
  else
  {
    printf("nope!\n");
  }

  printf("\n¯\\_(ツ)_/¯\n");
  return 0;
}

---

 ~ clang --version                                                             
                                                                    clang
version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
 ~ 

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151217/781055f8/attachment.html>


More information about the llvm-bugs mailing list