Opened 12 years ago

Last modified 11 years ago

#4988 new Feature Requests

[units] improve error messages when quantities are not convertible into one another.

Reported by: Alfredo Correa <alfredo.correa@…> Owned by: Steven Watanabe
Milestone: To Be Determined Component: units
Version: Boost 1.46.0 Severity: Problem
Keywords: conversion, error message Cc:

Description

Currently, if the quantities are not convertible one into the other (which depends on the included header, etc), the error message is pretty long and unreadable. Specifically in terms of what conversion is being attempted. I suggest the authors consider an improved compiler error message.

Attachments (1)

patch.tar.bz2 (15.9 KB ) - added by Benaka Moorthi <benaka.moorthi@…> 12 years ago.
contains patches to provide better error messages

Download all attachments as: .zip

Change History (5)

by Benaka Moorthi <benaka.moorthi@…>, 12 years ago

Attachment: patch.tar.bz2 added

contains patches to provide better error messages

comment:1 by Benaka Moorthi <benaka.moorthi@…>, 12 years ago

I've uploaded an archive w/ two patches that will provide better compiler error messages. GCC will now output error messages similar to those outputted by MSVC, and on every compiler, if derived dimension headers aren't included or the constructed dimension isn't named anywhere, the error message will no longer contain 'dim<X_base_dimension, static_rational<N, D> >' types, but instead 'X<N, D>' types. This should make it easier to see what's going on. I've included a README in the archive detailing my changes.

As an example, here is the new output when compiling & running the fail_implicit_conversion test using GCC: ...patience... ...found 719 targets... ...updating 3 targets... gcc.compile.c++ ../../../bin.v2/libs/units/test/fail_implicit_conversion.test/gcc-4.4.3/release/fail_implicit_conversion.o fail_implicit_conversion.cpp: In function ‘int main(int, char)’: fail_implicit_conversion.cpp:32: error: conversion from ‘const boost::units::quantity<boost::units::unit<boost::units::length_dimension, boost::units::si::system, void>, double>’ to non-scalar type ‘const boost::units::quantity<boost::units::unit<boost::units::length_dimension, boost::units::cgs::system, void>, double>’ requested

(failed-as-expected) ../../../bin.v2/libs/units/test/fail_implicit_conversion.test/gcc-4.4.3/release/fail_implicit_conversion.o passed ../../../bin.v2/libs/units/test/fail_implicit_conversion.test/gcc-4.4.3/release/fail_implicit_conversion.test ...updated 3 targets...

comment:2 by Steven Watanabe, 12 years ago

This doesn't exactly address what this ticket is about.

I'm somewhat concerned by BOOST_UNITS_REGISTER_DIM_ALIAS and friends, as they seems liable to produce ODR violations.

comment:3 by Benaka Moorthi <benaka.moorthi@…>, 12 years ago

I read the ticket description as an issue regarding the error messages in general, and since I started working w/ GCC, it made sense. If its regarding the instantiation backtrace that shows up when conversion_factor can't be called, this can be fixed fairly easily, so it would probably be faster if someone w/ commit access fixed it (as opposed to me submitting a patch & then someone applying it). And if its regarding something else entirely, its not something I can reproduce (at least w/o a test case).

As for the changes I posted, if there is interest in them, let me know. I should be able to fix the ODR issues and clean up my patch in the process. I can also add the conversion_factor fix.

comment:4 by Matthias Schabel, 11 years ago

Owner: changed from Matthias Schabel to Steven Watanabe
Note: See TracTickets for help on using tickets.