2 // RUN: split-file %s %t
4 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header -Werror=uninitialized folly-conv.h
5 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header -Werror=uninitialized thrift_cpp2_base.h
6 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header -Werror=uninitialized -fmodule-file=folly-conv.pcm -fmodule-file=thrift_cpp2_base.pcm logger_base.h
11 template <typename _Tp
, typename _Up
= _Tp
&&>
14 template <typename _Tp
>
15 auto declval() noexcept
-> decltype(__declval
<_Tp
>(0));
19 template <class Value
, class Error
>
22 auto thenOrThrow() -> decltype(declval
<Value
&>()) {
27 struct ExpectedHelper
{
28 template <class Error
, class T
>
29 static constexpr Expected
<T
, Error
> return_(T
) {
30 return Expected
<T
, Error
>();
33 template <class This
, class Fn
, class E
= int, class T
= ExpectedHelper
>
34 static auto then_(This
&&, Fn
&&)
35 -> decltype(T::template return_
<E
>((declval
<Fn
>()(true), 0))) {
36 return Expected
<int, int>();
41 inline Expected
<Tgt
, const char*> tryTo() {
43 // In build with asserts:
44 // clang/lib/Sema/SemaTemplateInstantiate.cpp: llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *clang::LocalInstantiationScope::findInstantiationOf(const Decl *): Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this scope"' failed.
45 // In release build compilation error on the line below inside lambda:
46 // error: variable 'result' is uninitialized when used here [-Werror,-Wuninitialized]
47 ExpectedHelper::then_(Expected
<bool, int>(), [&](bool) { return result
; });
56 // expected-no-diagnostics
61 // expected-no-diagnostics
63 //--- thrift_cpp2_base.h
66 // expected-no-diagnostics
70 import
"folly-conv.h";
71 import
"thrift_cpp2_base.h";
74 folly::tryTo
<unsigned>();
76 // expected-no-diagnostics