Skip to content

Commit 304c7a8

Browse files
authored
[flang][Evaluate] Restrict ConstantBase constructor overload (#138456)
ConstantBase has a constructor that takes a value of any type as an input: template <typename T> ConstantBase(const T &). A derived type Constant<T> is a member of many Expr<T> classes (as an alternative in the member variant). When trying (erroneously) to create Expr<T> from a wrong input, if the specific instance of Expr<T> contains Constant<T>, it's that constructor that will be instantiated, leading to cryptic and confusing errors. Eliminate the constructor from overload for invalid input values to help produce more meaningful diagnostics.
1 parent 96e0930 commit 304c7a8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

flang/include/flang/Evaluate/constant.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ class ConstantBase : public ConstantBounds {
110110
using Result = RESULT;
111111
using Element = ELEMENT;
112112

113-
template <typename A>
113+
// Constructor for creating ConstantBase from an actual value (i.e.
114+
// literals, etc.)
115+
template <typename A,
116+
typename = std::enable_if_t<std::is_convertible_v<A, Element>>>
114117
ConstantBase(const A &x, Result res = Result{}) : result_{res}, values_{x} {}
118+
115119
ConstantBase(ELEMENT &&x, Result res = Result{})
116120
: result_{res}, values_{std::move(x)} {}
117121
ConstantBase(

0 commit comments

Comments
 (0)