46 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// libc++ supports basic_format_string in C++20 as an extension12// UNSUPPORTED: !stdlib=libc++ && c++2013 14// <format>15 16// template<class charT, class... Args>17// class basic_format_string<charT, type_identity_t<Args>...>18//19// template<class T> consteval basic_format_string(const T& s);20//21// This constructor does the compile-time format string validation for the22// std::format* functions.23 24#include <format>25 26#include <string_view>27 28#include "test_macros.h"29 30void run() {31 (void)std::basic_format_string<char>{"foo"};32 (void)std::basic_format_string<char>{"{}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}33 (void)std::basic_format_string<char, int>{"{0:{0}P}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}34 (void)std::basic_format_string<char, int>{"{0:{0}}"};35 (void)std::basic_format_string<char, bool>{"{0:{0}}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}36 (void)std::basic_format_string<char, int>{"{.3}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}37#ifndef TEST_HAS_NO_WIDE_CHARACTERS38 (void)std::basic_format_string<wchar_t>{L"foo"};39 (void)std::basic_format_string<wchar_t>{L"{}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}40 (void)std::basic_format_string<wchar_t, int>{L"{0:{0}P}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}41 (void)std::basic_format_string<wchar_t, int>{L"{0:{0}}"};42 (void)std::basic_format_string<wchar_t, bool>{L"{0:{0}}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}43 (void)std::basic_format_string<wchar_t, int>{L"{.3}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}44#endif45}46