[clang] [clang] Use constant rounding mode for floating literals (PR #90877)

Joshua Cranmer via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 12:50:02 PDT 2024


================
@@ -79,3 +79,16 @@ float V7 = []() -> float {
   0x0.000001p0F);
 }();
 // CHECK: @V7 = {{.*}} float 1.000000e+00
+
+template<float V> struct L {
+  constexpr L() : value(V) {}
+  float value;
+};
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
----------------
jcranmer-intel wrote:

The interaction of these pragmas with C++ is underspecified, although for the most part, you can make pretty reasonable expectations about what the results should be. I'm also planning on bringing a paper to C++ to clarify the semantics somewhat, with the intent mostly being "just don't allow the pragma in most places."

That said, templates do add in all sorts of fun extra complexity, and there are at least three scenarios worth testing (with regards to interpretation of constants within the template body):
* Implicit template instantiation (you already test this)
* Explicit template instantiation
* Template specialization

I can definitely agree that implicit template instantiation should inherit from the rounding mode of the definition. Template specialization probably *shouldn't* inherit from the original template definition. Explicit instantiation... I'm not sure? I can argue that one either way.

https://github.com/llvm/llvm-project/pull/90877


More information about the cfe-commits mailing list