Skip to content

Commit

Permalink
Add clang for C++ CI (#32)
Browse files Browse the repository at this point in the history
* Add clang for C++ CI

* [bot][ubuntu] Generate current state of CWhy prompts (#33)

Co-authored-by: github-actions <[email protected]>

* Log more details on failure

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
3 people committed Sep 27, 2023
1 parent a9eefa7 commit 313fd82
Show file tree
Hide file tree
Showing 14 changed files with 855 additions and 3 deletions.
185 changes: 185 additions & 0 deletions tests/.regression/ubuntu/clang++-17/missing-hash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
===================== Prompt =====================
This is my code:

File `/home/runner/work/cwhy/cwhy/tests/c++/missing-hash.cpp`:
```
37 struct Node {
38 const std::pair<int, int> position;
39 std::vector<Node*> neighbors;
40 };
41
42 void bfs(Node* start, std::function<void(Node*)> f) {
43 std::unordered_set<std::pair<int, int>> visited;
44 std::queue<Node*> queue;
45 queue.push(start);
46
47 while (!queue.empty()) {
48 auto* n = queue.front();
49 queue.pop();
50 const auto [_, inserted] = visited.emplace(n->position);
51 if (inserted) {
52 f(n);
53 for (auto* neighbor : n->neighbors) {
```

File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unordered_set.h`:
```
93 template<typename _Value,
94 typename _Hash = hash<_Value>,
95 typename _Pred = equal_to<_Value>,
96 typename _Alloc = allocator<_Value>>
97 class unordered_set
98 {
99 typedef __uset_hashtable<_Value, _Hash, _Pred, _Alloc> _Hashtable;
100 _Hashtable _M_h;
101
102 public:
103 // typedefs:
```

File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unordered_set.h`:
```
129 using insert_return_type = typename _Hashtable::insert_return_type;
130 #endif
131
132 // construct/destroy/copy
133
134 /// Default constructor.
135 unordered_set() = default;
136
137 /**
138 * @brief Default constructor creates no elements.
```
File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unordered_set.h`:
```
372 *
373 * Insertion requires amortized constant time.
374 */
375 template<typename... _Args>
376 std::pair<iterator, bool>
377 emplace(_Args&&... __args)
378 { return _M_h.emplace(std::forward<_Args>(__args)...); }
379
380 /**
381 * @brief Attempts to insert an element into the %unordered_set.
```
File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h`:
```
176 * - __detail::_Equality
177 */
178 template<typename _Key, typename _Value, typename _Alloc,
179 typename _ExtractKey, typename _Equal,
180 typename _Hash, typename _RangeHash, typename _Unused,
181 typename _RehashPolicy, typename _Traits>
182 class _Hashtable
183 : public __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
184 _Hash, _RangeHash, _Unused, _Traits>,
185 public __detail::_Map_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
186 _Hash, _RangeHash, _Unused,
```

File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h`:
```
525 size_type __bkt_count_hint,
526 const _Hash&, const _Equal&, const allocator_type&,
527 false_type __uks);
528
529 public:
530 // Constructor, destructor, assignment, swap
531 _Hashtable() = default;
532
533 _Hashtable(const _Hashtable&);
```

File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h`:
```
945 public:
946 // Emplace
947 template<typename... _Args>
948 __ireturn_type
949 emplace(_Args&&... __args)
950 { return _M_emplace(__unique_keys{}, std::forward<_Args>(__args)...); }
951
952 template<typename... _Args>
953 iterator
```

File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h`:
```
2067 for (auto __it = begin(); __it != end(); ++__it)
2068 if (this->_M_key_equals(__k, *__it._M_cur))
2069 // There is already an equivalent node, no insertion
2070 return { __it, false };
2071 }
2072
2073 __hash_code __code = this->_M_hash_code(__k);
2074 size_type __bkt = _M_bucket_index(__code);
2075 if (size() > __small_size_threshold())
2076 if (__node_ptr __p = _M_find_node(__bkt, __k, __code))
```


This is my error:
```
/home/runner/work/cwhy/cwhy/tests/c++/missing-hash.cpp:43:45: error: call to implicitly-deleted default constructor of 'std::unordered_set<std::pair<int, int>>'
43 | std::unordered_set<std::pair<int, int>> visited;
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unordered_set.h:135:7: note: explicitly defaulted function was implicitly deleted here
135 | unordered_set() = default;
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unordered_set.h:100:18: note: default constructor of 'unordered_set<std::pair<int, int>>' is implicitly deleted because field '_M_h' has a deleted default constructor
100 | _Hashtable _M_h;
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h:531:7: note: explicitly defaulted function was implicitly deleted here
531 | _Hashtable() = default;
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h:183:7: note: default constructor of '_Hashtable<std::pair<int, int>, std::pair<int, int>, std::allocator<std::pair<int, int>>, std::__detail::_Identity, std::equal_to<std::pair<int, int>>, std::hash<std::pair<int, int>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true>>' is implicitly deleted because base class '__detail::_Hashtable_base<pair<int, int>, pair<int, int>, _Identity, equal_to<pair<int, int>>, hash<pair<int, int>>, _Mod_range_hashing, _Default_ranged_hash, _Hashtable_traits<true, true, true>>' has a deleted default constructor
183 | : public __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable_policy.h:1674:7: note: explicitly defaulted function was implicitly deleted here
1674 | _Hashtable_base() = default;
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable_policy.h:1632:7: note: default constructor of '_Hashtable_base<std::pair<int, int>, std::pair<int, int>, std::__detail::_Identity, std::equal_to<std::pair<int, int>>, std::hash<std::pair<int, int>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, true, true>>' is implicitly deleted because base class '_Hash_code_base<pair<int, int>, pair<int, int>, _Identity, hash<pair<int, int>>, _Mod_range_hashing, _Default_ranged_hash, _Hashtable_traits<true, true, true>::__hash_cached::value>' has a deleted default constructor
1632 | : public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable_policy.h:1261:7: note: explicitly defaulted function was implicitly deleted here
1261 | _Hash_code_base() = default;
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable_policy.h:1240:7: note: default constructor of '_Hash_code_base<std::pair<int, int>, std::pair<int, int>, std::__detail::_Identity, std::hash<std::pair<int, int>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>' is implicitly deleted because base class '_Hashtable_ebo_helper<1, hash<pair<int, int>>>' has a deleted destructor
1240 | : private _Hashtable_ebo_helper<1, _Hash>

[...]

In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/functional:61:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/unordered_map:46:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h:35:
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable_policy.h:1268:16: error: static assertion failed due to requirement 'std::__is_invocable<const std::hash<std::pair<int, int>> &, const std::pair<int, int> &>{}': hash function must be invocable with an argument of key type
1268 | static_assert(__is_invocable<const _Hash&, const _Key&>{},
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h:2073:29: note: in instantiation of member function 'std::__detail::_Hash_code_base<std::pair<int, int>, std::pair<int, int>, std::__detail::_Identity, std::hash<std::pair<int, int>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::_M_hash_code' requested here
2073 | __hash_code __code = this->_M_hash_code(__k);
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h:950:11: note: in instantiation of function template specialization 'std::_Hashtable<std::pair<int, int>, std::pair<int, int>, std::allocator<std::pair<int, int>>, std::__detail::_Identity, std::equal_to<std::pair<int, int>>, std::hash<std::pair<int, int>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true>>::_M_emplace<const std::pair<int, int> &>' requested here
950 | { return _M_emplace(__unique_keys{}, std::forward<_Args>(__args)...); }
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unordered_set.h:378:16: note: in instantiation of function template specialization 'std::_Hashtable<std::pair<int, int>, std::pair<int, int>, std::allocator<std::pair<int, int>>, std::__detail::_Identity, std::equal_to<std::pair<int, int>>, std::hash<std::pair<int, int>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true>>::emplace<const std::pair<int, int> &>' requested here
378 | { return _M_h.emplace(std::forward<_Args>(__args)...); }
| ^
/home/runner/work/cwhy/cwhy/tests/c++/missing-hash.cpp:50:44: note: in instantiation of function template specialization 'std::unordered_set<std::pair<int, int>>::emplace<const std::pair<int, int> &>' requested here
50 | const auto [_, inserted] = visited.emplace(n->position);
| ^
In file included from /home/runner/work/cwhy/cwhy/tests/c++/missing-hash.cpp:31:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/functional:61:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/unordered_map:46:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable.h:35:
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/hashtable_policy.h:1270:9: error: type 'const std::hash<std::pair<int, int>>' does not provide a call operator
1270 | return _M_hash()(__k);
| ^~~~~~~~~
3 errors generated.
```


What's the problem?
==================================================
114 changes: 114 additions & 0 deletions tests/.regression/ubuntu/clang++-17/missing-ostream-operator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
===================== Prompt =====================
This is my code:

File `/home/runner/work/cwhy/cwhy/tests/c++/missing-ostream-operator.cpp`:
```
23 private:
24 const std::string name;
25 const int age;
26 };
27
28 int main() {
29 Cat cat("Scott", 13);
30 std::cout << cat << std::endl;
31 }
```

File `/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/system_error`:
```
328 /** Write a std::error_code to an ostream.
329 *
330 * @relates error_code
331 * @since C++11
332 */
333 template<typename _CharT, typename _Traits>
334 basic_ostream<_CharT, _Traits>&
335 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
336 { return (__os << __e.category().name() << ':' << __e.value()); }
337
338 /** Class error_condition
```
This is my error:
```
/home/runner/work/cwhy/cwhy/tests/c++/missing-ostream-operator.cpp:30:15: error: invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'Cat')
30 | std::cout << cat << std::endl;
| ~~~~~~~~~ ^ ~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/system_error:335:5: note: candidate function template not viable: no known conversion from 'Cat' to 'const error_code' for 2nd argument
335 | operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
| ^ ~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:517:5: note: candidate function template not viable: no known conversion from 'Cat' to 'char' for 2nd argument
517 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
| ^ ~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:523:5: note: candidate function template not viable: no known conversion from 'Cat' to 'char' for 2nd argument
523 | operator<<(basic_ostream<char, _Traits>& __out, char __c)
| ^ ~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:534:5: note: candidate function template not viable: no known conversion from 'Cat' to 'signed char' for 2nd argument
534 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
| ^ ~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:539:5: note: candidate function template not viable: no known conversion from 'Cat' to 'unsigned char' for 2nd argument
539 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
| ^ ~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:615:5: note: candidate function template not viable: no known conversion from 'Cat' to 'const char *' for 2nd argument
615 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
| ^ ~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:628:5: note: candidate function template not viable: no known conversion from 'Cat' to 'const signed char *' for 2nd argument
628 | operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
| ^ ~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:633:5: note: candidate function template not viable: no known conversion from 'Cat' to 'const unsigned char *' for 2nd argument
633 | operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/ostream.tcc:307:5: note: candidate function template not viable: no known conversion from 'Cat' to 'const char *' for 2nd argument
307 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
| ^ ~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:507:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'Cat')
507 | operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
| ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/string_view:672:5: note: candidate template ignored: could not match 'basic_string_view<_CharT, _Traits>' against 'Cat'
672 | operator<<(basic_ostream<_CharT, _Traits>& __os,
| ^
[...]
178 | operator<<(short __n);
| ^ ~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:181:7: note: candidate function not viable: no known conversion from 'Cat' to 'unsigned short' for 1st argument
181 | operator<<(unsigned short __n)
| ^ ~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:189:7: note: candidate function not viable: no known conversion from 'Cat' to 'int' for 1st argument
189 | operator<<(int __n);
| ^ ~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:192:7: note: candidate function not viable: no known conversion from 'Cat' to 'unsigned int' for 1st argument
192 | operator<<(unsigned int __n)
| ^ ~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:201:7: note: candidate function not viable: no known conversion from 'Cat' to 'long long' for 1st argument
201 | operator<<(long long __n)
| ^ ~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:205:7: note: candidate function not viable: no known conversion from 'Cat' to 'unsigned long long' for 1st argument
205 | operator<<(unsigned long long __n)
| ^ ~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:220:7: note: candidate function not viable: no known conversion from 'Cat' to 'double' for 1st argument
220 | operator<<(double __f)
| ^ ~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:224:7: note: candidate function not viable: no known conversion from 'Cat' to 'float' for 1st argument
224 | operator<<(float __f)
| ^ ~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:232:7: note: candidate function not viable: no known conversion from 'Cat' to 'long double' for 1st argument
232 | operator<<(long double __f)
| ^ ~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:245:7: note: candidate function not viable: no known conversion from 'Cat' to 'const void *' for 1st argument; take the address of the argument with &
245 | operator<<(const void* __p)
| ^ ~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:250:7: note: candidate function not viable: no known conversion from 'Cat' to 'nullptr_t' (aka 'std::nullptr_t') for 1st argument
250 | operator<<(nullptr_t)
| ^ ~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ostream:283:7: note: candidate function not viable: no known conversion from 'Cat' to '__streambuf_type *' (aka 'basic_streambuf<char, std::char_traits<char>> *') for 1st argument
283 | operator<<(__streambuf_type* __sb);
| ^ ~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```
What's the problem?
==================================================
34 changes: 34 additions & 0 deletions tests/.regression/ubuntu/clang++-17/missing-struct-semicolon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
===================== Prompt =====================
This is my code:

File `/home/runner/work/cwhy/cwhy/tests/c++/missing-struct-semicolon.cpp`:
```
6 struct A {
7 }; // Add semicolon here
8
9 template <typename T>
10 ```
11 */
12 struct A {
13 }
14
15 template <typename T>
16 void f() {
```


This is my error:
```
/home/runner/work/cwhy/cwhy/tests/c++/missing-struct-semicolon.cpp:13:2: error: expected ';' after struct
13 | }
| ^

[...]

| ;
1 error generated.
```


What's the problem?
==================================================
Loading

0 comments on commit 313fd82

Please sign in to comment.