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

            Bug ID: 88371
           Summary: Gratuitous (?) warning regarding an implicit
                    conversion in pointer arithmetic
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eyalroz at technion dot ac.il
  Target Milestone: ---

See: https://godbolt.org/z/tYn9SX
for a live example and comparison with clang

Se: https://stackoverflow.com/q/53628998/1593077
for the question motivating this bug report.

-------

Consider the following program:

#include <iostream>

template <typename T>
struct wrapper {
    T t;
    operator T() const { return t; }
    T get() const { return t; }
};

int main() {
    int a[10];
    int* x { a } ;
    wrapper<long int> y1{2};
    wrapper<unsigned int> y2{2};
    wrapper<long unsigned int> y3{2};

    std::cout << (x + y1) << '\n';
    std::cout << (x + y2) << '\n';
    std::cout << (x + y3) << '\n'; // this triggers a warning
    std::cout << (x + y3.get()) << '\n';
}

When compiling it (with g++ 8.2.0) with -std=c++2a -Wsign-conversion we get:

a.cpp: In function ‘int main()’:
a.cpp:20:23: warning: conversion to ‘long int’ from ‘long unsigned int’ may
change the sign of the result [-Wsign-conversion]
     std::cout << (x + y3) << '\n'; // this triggers a warning
                       ^~
As far as I can tell, both the third and fourth line should trigger a warning,
or none of them should.

Also, a comment on the Stackoverflow page suggested this clause:
http://eel.is/c++draft/over.match.oper#9

may be relevant here.

Reply via email to