https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95892
Bug ID: 95892
Summary: Wrong line number in "-Wsign-conversion" 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 give the wrong line number in -Wsign-conversion
warning message.
$cat bug.cc
unsigned int var = 10;
void foo (
int a = var,
int b = var,
int c = var )
{ }
$g++ -c -Wsign-conversion bug.cc
bug.cc:5:17: warning: conversion to 'int' from 'unsigned int' may change the
sign of the result [-Wsign-conversion]
5 | int c = var )
| ^
bug.cc:5:17: warning: conversion to 'int' from 'unsigned int' may change the
sign of the result [-Wsign-conversion]
bug.cc:5:17: warning: conversion to 'int' from 'unsigned int' may change the
sign of the result [-Wsign-conversion]
While in clang
$clang++ -c -Wsign-conversion bug.cc
bug.cc:3:13: warning: implicit conversion changes signedness: 'unsigned int' to
'int' [-Wsign-conversion]
int a = var,
~ ^~~
bug.cc:4:13: warning: implicit conversion changes signedness: 'unsigned int' to
'int' [-Wsign-conversion]
int b = var,
~ ^~~
bug.cc:5:13: warning: implicit conversion changes signedness: 'unsigned int' to
'int' [-Wsign-conversion]
int c = var )
~ ^~~
3 warnings generated.
My GCC version is
$g++ --version
g++ (GCC) 11.0.0 20200605 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.