Skip to content

Commit 8ee1c16

Browse files
authored
Merge pull request diffblue#2340 from tautschnig/c++-cassert
C++ front-end: support =delete method declarations
2 parents 61ec7fc + 39a5631 commit 8ee1c16

File tree

18 files changed

+93
-23
lines changed

18 files changed

+93
-23
lines changed

regression/cbmc-cpp/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
default: tests.log
22

33
test:
4-
@../test.pl -c ../../../src/cbmc/cbmc
4+
@../test.pl -p -c ../../../src/cbmc/cbmc
55

66
tests.log: ../test.pl
7-
@../test.pl -c ../../../src/cbmc/cbmc
7+
@../test.pl -p -c ../../../src/cbmc/cbmc
88

99
show:
1010
@for dir in *; do \

regression/cbmc-cpp/MethodParam1/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
unsigned x;
33

44
class ct {
5+
public:
56
void f(int i) {
67
x=x+i;
78
}

regression/cpp/Method_qualifier1/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
class my_class
44
{

regression/cpp/auto1/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
const auto i=1;
44

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class A
2+
{
3+
public:
4+
void foo() {}
5+
};
6+
7+
class B : public A
8+
{
9+
public:
10+
void foo() = delete;
11+
};
12+
13+
int main()
14+
{
15+
B b;
16+
b.foo();
17+
18+
return 0;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.cpp
3+
-std=c++11
4+
^EXIT=(64|1)$
5+
^SIGNAL=0$
6+
not accessible
7+
--
8+
^warning: ignoring

regression/cpp/switch1/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
int main()
44
{

regression/systemc/Array1/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
#define COPY
44

regression/systemc/Array2/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
class myarray {
44

regression/systemc/Array3/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
#define FUNCTION
44

regression/systemc/Array4/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
#define CLASS
44

regression/systemc/BitvectorCpp1/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
int main(int argc, char** argv)
44
{

regression/systemc/BitvectorCpp2/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
int main(int argc, char** argv)
44
{

regression/systemc/This1/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <assert.h>
1+
#include <cassert>
22

33
class Foo;
44

src/ansi-c/scanner.l

+12-2
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,18 @@ and { return cpp98_keyword(TOK_ANDAND); }
749749
and_eq { return cpp98_keyword(TOK_ANDASSIGN); }
750750
bool { return cpp98_keyword(TOK_BOOL); }
751751
catch { return cpp98_keyword(TOK_CATCH); }
752-
char16_t { return cpp11_keyword(TOK_CHAR16_T); } // C++11
753-
char32_t { return cpp11_keyword(TOK_CHAR32_T); } // C++11
752+
char16_t { // C++11, but Visual Studio uses typedefs
753+
if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
754+
return make_identifier();
755+
else
756+
return cpp11_keyword(TOK_CHAR16_T);
757+
}
758+
char32_t { // C++11, but Visual Studio uses typedefs
759+
if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
760+
return make_identifier();
761+
else
762+
return cpp11_keyword(TOK_CHAR32_T);
763+
}
754764
class { return cpp98_keyword(TOK_CLASS); }
755765
compl { return cpp98_keyword('~'); }
756766
constexpr { return cpp11_keyword(TOK_CONSTEXPR); } // C++11

src/cpp/cpp_typecheck_compound_type.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@ void cpp_typecheckt::typecheck_compound_declarator(
450450

451451
if(is_method)
452452
{
453+
if(
454+
value.id() == ID_code &&
455+
to_code(value).get_statement() == ID_cpp_delete)
456+
{
457+
value.make_nil();
458+
component.set(ID_access, "noaccess");
459+
}
460+
453461
component.set(ID_is_inline, declaration.member_spec().is_inline());
454462

455463
// the 'virtual' name of the function
@@ -1487,13 +1495,11 @@ bool cpp_typecheckt::get_component(
14871495
}
14881496
else
14891497
{
1490-
#if 0
14911498
error().source_location=source_location;
1492-
str << "error: member `" << component_name
1493-
<< "' is not accessible (" << component.get(ID_access) << ")";
1494-
str << "\nstruct name: " << final_type.get(ID_name);
1499+
error() << "error: member `" << component_name
1500+
<< "' is not accessible (" << component.get(ID_access) << ")"
1501+
<< eom;
14951502
throw 0;
1496-
#endif
14971503
}
14981504
}
14991505

@@ -1523,12 +1529,10 @@ bool cpp_typecheckt::get_component(
15231529
{
15241530
if(check_component_access(component, final_type))
15251531
{
1526-
#if 0
15271532
error().source_location=source_location;
1528-
str << "error: member `" << component_name
1529-
<< "' is not accessible";
1533+
error() << "error: member `" << component_name
1534+
<< "' is not accessible" << eom;
15301535
throw 0;
1531-
#endif
15321536
}
15331537

15341538
if(object.get_bool(ID_C_lvalue))

src/cpp/parse.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -2494,13 +2494,25 @@ bool Parser::rConstructorDecl(
24942494

24952495
case TOK_DEFAULT: // C++0x
24962496
{
2497+
if(!ansi_c_parser.cpp11)
2498+
{
2499+
SyntaxError();
2500+
return false;
2501+
}
2502+
24972503
constructor.value()=codet(ID_default);
24982504
set_location(constructor.value(), value);
24992505
}
25002506
break;
25012507

25022508
case TOK_DELETE: // C++0x
25032509
{
2510+
if(!ansi_c_parser.cpp11)
2511+
{
2512+
SyntaxError();
2513+
return false;
2514+
}
2515+
25042516
constructor.value()=codet(ID_cpp_delete);
25052517
set_location(constructor.value(), value);
25062518
}
@@ -2675,12 +2687,24 @@ bool Parser::rDeclaratorWithInit(
26752687

26762688
if(lex.LookAhead(0)==TOK_DEFAULT) // C++0x
26772689
{
2690+
if(!ansi_c_parser.cpp11)
2691+
{
2692+
SyntaxError();
2693+
return false;
2694+
}
2695+
26782696
lex.get_token(tk);
26792697
declarator.value()=codet(ID_default);
26802698
set_location(declarator.value(), tk);
26812699
}
26822700
else if(lex.LookAhead(0)==TOK_DELETE) // C++0x
26832701
{
2702+
if(!ansi_c_parser.cpp11)
2703+
{
2704+
SyntaxError();
2705+
return false;
2706+
}
2707+
26842708
lex.get_token(tk);
26852709
declarator.value()=codet(ID_cpp_delete);
26862710
set_location(declarator.value(), tk);

src/util/config.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,11 @@ configt::cppt::cpp_standardt configt::cppt::default_cpp_standard()
663663
// g++ 6.3 uses gnu++14
664664
// g++ 5.4 uses gnu++98
665665
// clang 6.0 uses c++14
666+
#if defined _WIN32
667+
return cpp_standardt::CPP14;
668+
#else
666669
return cpp_standardt::CPP98;
670+
#endif
667671
}
668672

669673
void configt::set_arch(const irep_idt &arch)

0 commit comments

Comments
 (0)