C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] Templated compile-time warnings, errors and messages
From: Alexis Paques (alexis.paques_at_[hidden])
Date: 2020-07-20 09:40:52


Hello,

We would like to provide the user of a library with information more
precise and concise than the template failure.
The same we used to call #warning and #error, we would like to
provide compile-time warnings when using if constexpr.

The solution proposed online is to artificially cause a known warning with
some message doing something like:

template < typename T >
auto compute(T data) {
  if constexpr(std::is_array < T > ::value) {
      // Some implementation
  } else {
    int method_not_implemented;
  }
}

Instead, we would like to provide more comprehensive feedback.
The proposed solution is to add custom compiler warnings with a new code to
text functionality.

template < typename T >
auto compute(T data) {
  if constexpr(std::is_array < T > ::value) {
      std::constexpr_warning("arbitrary_company_experimental", "The
implementation of " std::expr_type_to_text<T>() " is experimental.");
  } else {

 std::constexpr_error("arbitrary_company_error", "The "
std::expr_type_to_text<T>() " type is not supported.");
  }
}



STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups