Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preprocessor directives in a macro argument list is UB #24

Closed
BobSteagall opened this issue Apr 23, 2020 · 1 comment
Closed

preprocessor directives in a macro argument list is UB #24

BobSteagall opened this issue Apr 23, 2020 · 1 comment

Comments

@BobSteagall
Copy link

The use of preprocessor directives within the macro argument list in lines 206-211 of layout_stride.hpp is undefined behavior. Please consider applying the following patch, which wraps the entirety of the MDSPAN_FUNCTION_REQUIRES macro invocation inside the #if/#else clauses:

--- layout_stride.hpp-orig      2020-04-23 14:59:54.000000000 -0400
+++ layout_stride.hpp   2020-04-23 15:02:54.000000000 -0400
@@ -198,19 +198,27 @@

   // TODO @proposal-bug @proposal-extension layout stride needs this constructor
   // clang-format off
+#if defined(__INTEL_COMPILER)
   MDSPAN_FUNCTION_REQUIRES(
     (MDSPAN_INLINE_FUNCTION constexpr explicit),
     layout_stride_impl, (std::experimental::extents<Exts...> const& e), noexcept,
     /* requires */ (
       // remember that this also covers the zero strides case because an && fold on an empty pack is true
-#if defined(__INTEL_COMPILER)
       // Work-around for an ICE. layout_stride won't properly SFINAE with ICC, but oh well
       true
+    )
+  )
 #else
+  MDSPAN_FUNCTION_REQUIRES(
+    (MDSPAN_INLINE_FUNCTION constexpr explicit),
+    layout_stride_impl, (std::experimental::extents<Exts...> const& e), noexcept,
+    /* requires */ (
+      // remember that this also covers the zero strides case because an && fold on an empty pack is true
       _MDSPAN_FOLD_AND(Strides != dynamic_extent /* && ... */)
-#endif
     )
-  ) : __base_t(__base_t{__member_pair_t(e, __strides_storage_t())})
+  )
+#endif
+  : __base_t(__base_t{__member_pair_t(e, __strides_storage_t())})
   { }
   // clang-format on

@@ -323,4 +331,4 @@
 };

 } // end namespace experimental
-} // end namespace std
\ No newline at end of file
+} // end namespace std
@dhollman
Copy link
Contributor

Yeah, I didn't realize this. This is now fixed by #21. Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants