https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95831

            Bug ID: 95831
           Summary: Wrong line number in " -Wconversion" warning message
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
                CC: mpolacek at gcc dot gnu.org
  Target Milestone: ---

This code, bug.cc, GCC might emit the wrong line number of the "-Wconversion"
warning.

$cat bug.cc
unsigned a = 0;
void foo (
    short  param1 = a,
    short  param2 = a,
    char param3 = a)
{    }

$g++ -Wconversion -c bug.cc
bug.cc:6:20: warning: conversion from 'unsigned int' to 'short int' may change
value [-Wconversion]
    6 |     char param3 = a)
      |                    ^
bug.cc:6:20: warning: conversion from 'unsigned int' to 'short int' may change
value [-Wconversion]
bug.cc:6:20: warning: conversion from 'unsigned int' to 'char' may change value
[-Wconversion]
Compiler returned: 0

While in Clang:
$clang++ -Wconversion -c bug.cc
bug.cc:3:21: warning: implicit conversion loses integer precision: 'unsigned
int' to 'short' [-Wimplicit-int-conversion]
    short  param1 = a,
                  ~ ^
bug.cc:4:21: warning: implicit conversion loses integer precision: 'unsigned
int' to 'short' [-Wimplicit-int-conversion]
    short  param2 = a,
                  ~ ^
bug.cc:5:19: warning: implicit conversion loses integer precision: 'unsigned
int' to 'char' [-Wimplicit-int-conversion]
    char param3 = a)
                ~ ^
3 warnings generated.

Reproduced in godblot: https://godbolt.org/z/AoGkVQ

Noted that I have tested it in almost all GCC versions, they all have this
issue. I guess maybe someone have reported this already, but I can't find one.

Reply via email to