================
@@ -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) {}
+   };
+
+   // User-defined deduction guide
+   template <typename T>
+   MyType(T) -> MyType<T>;
----------------
yxsamliu wrote:

It seems nvcc just treats deduction guide as host+device and silently ignores 
host/device attributes on the deduction guide 
(https://godbolt.org/z/8s74G7vvh). If we emit warnings for host/device attrs on 
deduction guide, CUDA programs that  can be compiled by nvcc may fail with 
clang under -Wall.

https://github.com/llvm/llvm-project/pull/168711
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to