| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| // See https://llvm.org/LICENSE.txt for license information. |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| // RUN: cxx_compiler cxx_11 -c %s -o %t.o |
| // RUN: bindump %t.o | FileCheck prefixes %s |
| |
| // Literals in expressions. |
| // CHECK-DAG: _Z1fIiEvRAszplcvT__EngLi42E_c |
| // NB no negative integer literals |
| template <class T> void f(char (&buffer)[sizeof(T() + -42)]) {} |
| void call_f() { |
| char buffer[sizeof(int)]; |
| f<int>(buffer); |
| } |
| |
| // float |
| // CHECK-DAG: _Z1gIfEvRAszplcvT__ELf40a00000E_c |
| template <class T> void g(char (&buffer)[sizeof(T() + 5.0f)]) {} |
| void call_g() { |
| char buffer[sizeof(float)]; |
| g<float>(buffer); |
| } |
| |
| // negative float (uses unary negation) |
| // CHECK-DAG: _Z2g2IfEvRAszplcvT__EngLf3f800000E_c |
| template <class T> void g2(char (&buffer)[sizeof(T() + -1.0f)]) {} |
| void call_g2() { |
| char buffer[sizeof(float)]; |
| g2<float>(buffer); |
| } |
| |
| // CHECK-DAG: _Z2g3IdEvRAszplcvT__ELd4014000000000000E_c |
| template <class T> void g3(char (&buffer)[sizeof(T() + 5.0)]) {} |
| void call_g3() { |
| char buffer[sizeof(double)]; |
| g3<double>(buffer); |
| } |
| |
| |
| // Generate raw pointer literal expression nullptr (rather than template argument that happens to be a null pointer). |
| // CHECK-DAG: _Z1hIiEvRAszcvPT_LDnE_c |
| template <class T> void h(char (&buffer)[sizeof((T*)nullptr)]) {} |
| void call_h() { |
| char buffer[sizeof((int*)nullptr)]; |
| h<int>(buffer); |
| } |
| |
| // string literals |
| // CHECK-DAG: _Z3fooIiEDTcl3barfp_LA4_KwEEET_ |
| int bar(int x, const wchar_t *); |
| template<class T> auto foo(T x) -> decltype(bar(x, L"abc")); |
| template <> auto foo<int>(int x) -> decltype(bar(x, L"abc")) { return 0; } |
| |
| // CHECK-DAG: _Z4foo1IfEDTcl4bar1fp_LA5_KcEEET_ |
| float bar1(float x, const char *); |
| template<class T> auto foo1(T x) -> decltype(bar1(x, "abcd")); |
| template <> auto foo1<float>(float x) -> decltype(bar1(x, "abcd")) { return 0; } |