This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/24525] New: g++ fails to warn when converting UDT through double to int


g++-4.0.0 compiles the following code without warning, with both -Wconversion
and -Wall turned on. Since it is converting the UDT into a double, then
converting the double to an int, I believe it should warn exactly as it does in
the case when the commented-out line is used in place of the direct assignment.

monsterd07> g++ -Wall test.C
monsterd07> ./a.out
monsterd07> g++ --version
g++ (GCC) 3.3.4 (pre 3.3.5 20040809)
Copyright (C) 2003 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.

(test.C)
#include <assert.h>

struct T {
  explicit T(int i): mV(i) {}

  operator double() const {
    return mV;
  }

  int mV;
};

int main() {
  T t(5);
  int y = t;
  // int y = double(t);
  assert(y == 5);
}


-- 
           Summary: g++ fails to warn when converting UDT through double to
                    int
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: georgeh at rentec dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24525


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]