[LLVMbugs] [Bug 11313] New: warning with conditional operator and printf

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 4 11:15:38 PDT 2011


             Bug #: 11313
           Summary: warning with conditional operator and printf
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: loox at e-shell.net
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The is a false positive in the format checker, when using conditional operator
and parameters get promoted.

There is more info in this thread:



clang -Wall -o ntohs2 ntohs2.c 
ntohs2.c:10:12: warning: conversion specifies type 'unsigned short' but the 
argument has type
      'int' [-Wformat]
        printf("%hu\n", x < 0 ? x : y);
                ~~^     ~~~~~~~~~~~~~
1 warning generated.


#include <stdio.h>
#include <netinet/in.h>

int main()
    uint16_t x = htons(80);
    uint16_t y = ntohs(80);
    x = x < 0 ? x : y;
    printf("%hu\n", y);
    printf("%hu\n", x < 0 ? x : y);
    return (0);

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list