================
@@ -287,6 +287,46 @@ Example Usage
basePtr->virtualFunction(); // Allowed since obj is constructed in
device code
}
+C++17 Class Template Argument Deduction (CTAD) Support
+======================================================
+
+Clang supports C++17 Class Template Argument Deduction (CTAD) in both host and
device code for HIP.
+This allows you to omit template arguments when creating class template
instances, letting the compiler
+deduce them from constructor arguments.
+
+.. code-block:: c++
+
+ #include <tuple>
+
+ __host__ __device__ void func() {
+ std::tuple<int, int> t = std::tuple(1, 1);
+ }
+
+In the above example, ``std::tuple(1, 1)`` automatically deduces the type to
be ``std::tuple<int, int>``.
+
+Deduction Guides
+----------------
+
+User-defined deduction guides are also supported. Since deduction guides are
not executable code and only
+participate in type deduction, they are treated as ``__host__ __device__`` by
the compiler, regardless of
+explicit target attributes. This ensures they are available for deduction in
both host and device contexts.
+
+.. code-block:: c++
+
+ template <typename T>
+ struct MyType {
+ T value;
+ MyType(T v) : value(v) {}
----------------
Artem-B wrote:
constructor should be invocable on the GPU, otherwise the sample does not
compile: https://godbolt.org/z/PYo3n5aGK
https://github.com/llvm/llvm-project/pull/168711
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits