Skip to content

Commit 91a4196

Browse files
committed
Minor tidying
Update comments, and move more sema checks to `sema.h` in preparation for more metatype functions in the summer that may want to take 'grammar-legal but sema-illegal' type grammar as input, and transform them to sema-legal actual type bodies
1 parent be2b41f commit 91a4196

File tree

8 files changed

+214
-40
lines changed

8 files changed

+214
-40
lines changed

include/cpp2util.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ class out {
690690
#define CPP2_FORCE_INLINE_LAMBDA __attribute__((always_inline))
691691

692692
#if defined(__clang_major__)
693-
#if (__clang_major__ > 13 || (__clang_major__ == 13 && __clang_minor__ >= 2))
693+
// Also check __cplusplus, only to satisfy Clang -pedantic-errors
694+
#if __cplusplus >= 202302L && (__clang_major__ > 13 || (__clang_major__ == 13 && __clang_minor__ >= 2))
694695
#define CPP2_LAMBDA_NO_DISCARD [[nodiscard]]
695696
#else
696697
#define CPP2_LAMBDA_NO_DISCARD
@@ -1351,13 +1352,12 @@ constexpr auto as( X const& x ) -> decltype(auto)
13511352

13521353
//-----------------------------------------------------------------------
13531354
//
1354-
// A variation of GSL's final_action_success and finally to run only on success
1355-
// (based on a PR I contributed to Microsoft GSL)
1355+
// A variation of GSL's final_action_success / finally
13561356
//
1357-
// final_action_success ensures something is run at the end of a scope
1358-
// if no exception is thrown
1357+
// finally ensures something is run at the end of a scope always
13591358
//
1360-
// finally_success is a convenience function to make a final_action_success_success
1359+
// finally_success ensures something is run at the end of a scope
1360+
// if no exception is thrown
13611361
//
13621362
//-----------------------------------------------------------------------
13631363
//
@@ -1391,10 +1391,6 @@ class finally_success
13911391
};
13921392

13931393

1394-
//
1395-
// Same, but clean up also on exceptional paths
1396-
//
1397-
13981394
template <class F>
13991395
class finally
14001396
{

regression-tests/pure2-ufcs-member-access-and-chaining.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ main: () -> int = {
1818

1919
_ = (j.i).ufcs();
2020

21-
_ = 42.no_return();
21+
42.no_return();
2222
}
2323

2424
no_return: (x: int) = { }

regression-tests/test-results/pure2-ufcs-member-access-and-chaining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extern int y;
5858

5959
(void) CPP2_UFCS_0(ufcs, (std::move(j).i));
6060

61-
(void) CPP2_UFCS_0(no_return, 42);
61+
CPP2_UFCS_0(no_return, 42);
6262
}
6363

6464
auto no_return(cpp2::in<int> x) -> void{}

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8611:0927
2+
cppfront compiler v0.2.1 Build 8613:1951
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8611:0927"
1+
"8613:1951"

source/cppfront.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,6 +3680,10 @@ class cppfront
36803680
)
36813681
-> void
36823682
{
3683+
if (!sema.check(n)) {
3684+
return;
3685+
}
3686+
36833687
auto emit_parameters =
36843688
!n.emitted
36853689
&& n.parameters
@@ -4769,7 +4773,13 @@ class cppfront
47694773
)
47704774
-> void
47714775
{
4772-
if (!sema.check(n)) {
4776+
// Declarations are handled in multiple passes,
4777+
// but we only want to do the sema checks once
4778+
if (
4779+
printer.get_phase() == printer.phase1_type_defs_func_decls
4780+
&& !sema.check(n)
4781+
)
4782+
{
47734783
return;
47744784
}
47754785

@@ -4950,9 +4960,14 @@ class cppfront
49504960

49514961
for (auto& stmt : compound_stmt->statements)
49524962
{
4963+
if (!stmt->is_declaration()) {
4964+
// We will already have emitted an error for this in sema.check
4965+
return;
4966+
}
49534967
auto& decl = std::get<statement_node::declaration>(stmt->statement);
49544968
assert(decl);
49554969
assert(decl->name());
4970+
49564971
auto emit_as_base =
49574972
decl->get_decl_if_type_scope_object_name_before_a_base_type(*decl->name());
49584973

@@ -5092,10 +5107,7 @@ class cppfront
50925107
{
50935108
assert(stmt);
50945109
if (!stmt->is_declaration()) {
5095-
errors.emplace_back(
5096-
stmt->position(),
5097-
"a user-defined type body must contain only declarations, not other code"
5098-
);
5110+
// We will already have emitted an error for this in sema.check
50995111
return;
51005112
}
51015113

0 commit comments

Comments
 (0)