[llvm] r225053 - Add an ArrayRef upcasting constructor from ArrayRef<U*> -> ArrayRef<T*> where T is a base of U.
Kuperstein, Michael M
michael.m.kuperstein at intel.com
Thu Jan 1 01:41:53 PST 2015
Hello Michael,
Looks like this broke the build for MSVC, just about everything that includes SelectionDAG.h hits this:
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\type_traits(1348): error C2139: 'llvm::SDDbgValue' : an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of'
1> C:\llvm\rw\include\llvm/CodeGen/SelectionDAG.h(38) : see declaration of 'llvm::SDDbgValue'
1> C:\llvm\rw\include\llvm/CodeGen/SelectionDAG.h(149) : see reference to class template instantiation 'std::is_base_of<llvm::SDDbgValue,_Ty>' being compiled
1> with
1> [
1> _Ty=llvm::SDDbgValue
1> ]
Thanks,
Michael
-----Original Message-----
From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Michael Gottesman
Sent: Thursday, January 01, 2015 01:33
To: llvm-commits at cs.uiuc.edu
Subject: [llvm] r225053 - Add an ArrayRef upcasting constructor from ArrayRef<U*> -> ArrayRef<T*> where T is a base of U.
Author: mgottesman
Date: Wed Dec 31 17:33:18 2014
New Revision: 225053
URL: http://llvm.org/viewvc/llvm-project?rev=225053&view=rev
Log:
Add an ArrayRef upcasting constructor from ArrayRef<U*> -> ArrayRef<T*> where T is a base of U.
Modified:
llvm/trunk/include/llvm/ADT/ArrayRef.h
llvm/trunk/unittests/ADT/ArrayRefTest.cpp
Modified: llvm/trunk/include/llvm/ADT/ArrayRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=225053&r1=225052&r2=225053&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
+++ llvm/trunk/include/llvm/ADT/ArrayRef.h Wed Dec 31 17:33:18 2014
@@ -112,6 +112,16 @@ namespace llvm {
std::is_convertible<U *const *, T const *>::value>::type* = 0)
: Data(A.data()), Length(A.size()) {}
+ /// Construct an ArrayRef<T*> from an ArrayRef<U*> where T is a super class
+ /// of U. This uses SFINAE to ensure that only ArrayRefs with this property
+ /// can be converted. This is an upcasting constructor.
+ template <typename U>
+ ArrayRef(const ArrayRef<U> &A,
+ typename std::enable_if<std::is_base_of<
+ typename std::remove_pointer<T>::type,
+ typename std::remove_pointer<U>::type>::value>::type * = 0)
+ : Data(reinterpret_cast<T const *>(A.data())), Length(A.size()) {}
+
/// @}
/// @name Simple Operations
/// @{
Modified: llvm/trunk/unittests/ADT/ArrayRefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/ArrayRefTest.cpp?rev=225053&r1=225052&r2=225053&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/ArrayRefTest.cpp (original)
+++ llvm/trunk/unittests/ADT/ArrayRefTest.cpp Wed Dec 31 17:33:18 2014
@@ -90,4 +90,39 @@ TEST(ArrayRefTest, ConstConvert) {
a = ArrayRef<int *>(A);
}
+struct A {
+ int data;
+
+ A() : data(0) {}
+};
+
+struct B : A {
+ int data2;
+
+ B() : A(), data2(0) {}
+};
+
+TEST(ArrayRefTest, UpcastConvert) {
+ B Data[5];
+
+ for (unsigned i = 0, e = 5; i != e; ++i) {
+ Data[i].data = i + 5;
+ Data[i].data2 = i + 30;
+ }
+
+ B *DataPtrs[5];
+ for (unsigned i = 0, e = 5; i != e; ++i) {
+ DataPtrs[i] = &Data[i];
+ }
+
+ ArrayRef<B *> BArray(DataPtrs, 5);
+ ArrayRef<A *> AArray(BArray);
+
+ EXPECT_TRUE(AArray.size() == 5);
+ for (unsigned i = 0, e = 5; i != e; ++i) {
+ A *a = AArray[i];
+ EXPECT_TRUE(a->data == int(i + 5));
+ }
+}
+
} // end anonymous namespace
_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
---------------------------------------------------------------------
Intel Israel (74) Limited
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
More information about the llvm-commits
mailing list