https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111474
Bug ID: 111474 Summary: Consider stripping from the error message the identifiers of namespaces brought with using-directives Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mateusz.pusz at gmail dot com Target Milestone: --- It would be awesome if the compiler was able to strip the identifiers for namespaces brought with using-directive in the source code that produces an error. It does it for some, but not all names already. If the full names are considered useful in some scenarios (to better point to the source type in an unknown code base), maybe a command line option for the verbosity of messages could be introduced? Let's consider the following example: ```cpp using namespace mp_units; using namespace mp_units::si::unit_symbols; auto q = (5 * m) * (1. * s); quantity<si::metre / si::second> v1 = q; quantity<isq::speed[m / s]> v2 = q; ``` `quantity` in the above code is declared in the `mp_units` namespace but in the following error messages, it is printed without the namespace identifier, which is awesome. However, the rest of the identifiers from this namespace (even though it is brought to the current scope with the using-directive are using this namespace identifier). ``` <source>: In function 'int main()': <source>:9:41: error: conversion from 'quantity<mp_units::derived_unit<mp_units::si::metre, mp_units::si::second>(),[...]>' to non-scalar type 'quantity<mp_units::derived_unit<mp_units::si::metre, mp_units::per<mp_units::si::second> >(),[...]>' requested 9 | quantity<si::metre / si::second> v1 = q; | ^ <source>:10:36: error: conversion from 'quantity<mp_units::derived_unit<mp_units::si::metre, mp_units::si::second>(),[...]>' to non-scalar type 'quantity<mp_units::reference<mp_units::isq::speed(), mp_units::derived_unit<mp_units::si::metre, mp_units::per<mp_units::si::second> >()>(),[...]>' requested 10 | quantity<isq::speed[m / s]> v2 = q; | ^ Compiler returned: 1 ``` If the compiler was able to strip such namespaces, the error message would look like this: ``` <source>: In function 'int main()': <source>:9:41: error: conversion from 'quantity<derived_unit<si::metre, si::second>(),[...]>' to non-scalar type 'quantity<derived_unit<si::metre, per<si::second> >(),[...]>' requested 9 | quantity<si::metre / si::second> v1 = q; | ^ <source>:10:36: error: conversion from 'quantity<derived_unit<si::metre, si::second>(),[...]>' to non-scalar type 'quantity<reference<isq::speed(), derived_unit<si::metre, per<si::second> >()>(),[...]>' requested 10 | quantity<isq::speed[m / s]> v2 = q; | ^ Compiler returned: 1 ``` which is much terser and easier to read. As the user brings the `mp-units` namespace to the current scope, he/she should not be surprised by the meaning of the shorter type identifiers and would certainly appreciate easier-to-understand error messages. Please note that GCC already removed some important information from the error messages with the `[...]` anyway now, so there is a precedence for preferring terse error messages already. Consider also how it would improve error messages for `std::filesystem` of `std::chrono` in the standard library. As they are quite long, users already often bring them in the current scope with the using-declaration or use namespace aliases, which is probably too much for the error message generator to follow?