C++ Logo

std-proposals

Advanced search

Templated compile-time warnings, errors and messages

From: Alexis Paques <alexis.paques_at_[hidden]>
Date: Mon, 20 Jul 2020 16:40:52 +0200
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.");
  }
}

Received on 2020-07-20 09:44:21