[PATCH] D51262: Implement P0553 and P0556

Marshall Clow via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 24 19:40:51 PDT 2019


mclow.lists marked an inline comment as done.
mclow.lists added inline comments.


================
Comment at: libcxx/include/bit:378
+    	const unsigned __retVal = 1u << (__n + __extra);
+    	return (_Tp) (__retVal >> __extra);
+    }
----------------
mclow.lists wrote:
> Quuxplusone wrote:
> > Why so complicated? Is there a unit test that demonstrates why you can't just use `return _Tp{1} << __n;` in this case as well?
> > 
> > Also, is this a kosher use of `sizeof(X) * 8` as a stand-in for `numeric_limits<X>::digits`?
> > 
> > Also, speaking of unit tests, I don't see any unit tests for e.g. `std::ceil2(256)` or `std::ceil2(65536)`. Shouldn't there be some?
> Yes. I want to generate some UB here, so that this is not a "core constant expression" as per P1355.
Yes, the `ceil2.fail.cpp` test will not fail (for short types) if I just return `_Tp{1} << __n;` - because of integer promotion.



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D51262/new/

https://reviews.llvm.org/D51262





More information about the cfe-commits mailing list