This repository was archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile_error.cpp
More file actions
51 lines (44 loc) · 1.69 KB
/
compile_error.cpp
File metadata and controls
51 lines (44 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// cpp-flexargs
//
// Copyright iorate 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <iostream>
#include <utility>
#include "../flexargs.hpp"
using namespace flexargs;
namespace keywords {
inline constexpr keyword<struct x_> x;
inline constexpr keyword<struct y_> y;
}
template <class ...Args> // In Python:
void f(Args &&...args) { // def f(x, y):
auto [x, y] = match(
parameter(keywords::x),
parameter(keywords::y),
std::forward<Args>(args)...
);
std::cout << "x = " << x << "\n";
std::cout << "y = " << y << "\n";
}
int main() {
using namespace keywords;
f(1, 2, x = 3);
}
/*
$ g++ -std=c++17 compile_error.cpp
compile_error.cpp: In instantiation of 'void f(Args&& ...) [with Args = {int, int, flexargs::detail::keyword_argument<keywords::x_, int>}]':
compile_error.cpp:32:18: required from here
compile_error.cpp:21:10: error: cannot decompose class type 'flexargs::detail::syntax_error<flexargs::detail::duplicate_argument<keywords::x_> >' without non-static data members
auto [x, y] = match(
^~~~~~
$ clang++ -std=c++17 compile_error.cpp
compile_error.cpp:21:10: error: type 'flexargs::detail::syntax_error<flexargs::detail::duplicate_argument<keywords::x_> >' decomposes into 0 elements, but 2 names were provided
auto [x, y] = match(
^
compile_error.cpp:32:5: note: in instantiation of function template specialization 'f<int, int, flexargs::detail::keyword_argument<keywords::x_, int> >' requested here
f(1, 2, x = 3);
^
1 error generated.
*/