Skip to content

Commit

Permalink
C++ front-end: support =delete method declarations
Browse files Browse the repository at this point in the history
This enables us to use use cassert instead of assert.h in C++ regression tests,
as Visual Studio's header files make use of this. =delete and =default are C++11
(and later) only, make sure the parser is sufficiently restrictive.
  • Loading branch information
tautschnig committed Jun 13, 2018
1 parent e3de3f6 commit fafe4d9
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion regression/cpp/Method_qualifier1/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

class my_class
{
Expand Down
2 changes: 1 addition & 1 deletion regression/cpp/auto1/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

const auto i=1;

Expand Down
19 changes: 19 additions & 0 deletions regression/cpp/deleted_function1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class A
{
public:
void foo() {}
};

class B : public A
{
public:
void foo() = delete;
};

int main()
{
B b;
b.foo();

return 0;
}
8 changes: 8 additions & 0 deletions regression/cpp/deleted_function1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.cpp
-std=c++11
^EXIT=(64|1)$
^SIGNAL=0$
not accessible
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cpp/switch1/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion regression/systemc/Array1/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

#define COPY

Expand Down
2 changes: 1 addition & 1 deletion regression/systemc/Array2/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

class myarray {

Expand Down
2 changes: 1 addition & 1 deletion regression/systemc/Array3/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

#define FUNCTION

Expand Down
2 changes: 1 addition & 1 deletion regression/systemc/Array4/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

#define CLASS

Expand Down
2 changes: 1 addition & 1 deletion regression/systemc/BitvectorCpp1/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

int main(int argc, char** argv)
{
Expand Down
2 changes: 1 addition & 1 deletion regression/systemc/BitvectorCpp2/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

int main(int argc, char** argv)
{
Expand Down
2 changes: 1 addition & 1 deletion regression/systemc/This1/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <cassert>

class Foo;

Expand Down
8 changes: 8 additions & 0 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ void cpp_typecheckt::typecheck_compound_declarator(

if(is_method)
{
if(
value.id() == ID_code &&
to_code(value).get_statement() == ID_cpp_delete)
{
value.make_nil();
component.set(ID_access, "noaccess");
}

component.set(ID_is_inline, declaration.member_spec().is_inline());

// the 'virtual' name of the function
Expand Down
24 changes: 24 additions & 0 deletions src/cpp/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2494,13 +2494,25 @@ bool Parser::rConstructorDecl(

case TOK_DEFAULT: // C++0x
{
if(!ansi_c_parser.cpp11)
{
SyntaxError();
return false;
}

constructor.value()=codet(ID_default);
set_location(constructor.value(), value);
}
break;

case TOK_DELETE: // C++0x
{
if(!ansi_c_parser.cpp11)
{
SyntaxError();
return false;
}

constructor.value()=codet(ID_cpp_delete);
set_location(constructor.value(), value);
}
Expand Down Expand Up @@ -2675,12 +2687,24 @@ bool Parser::rDeclaratorWithInit(

if(lex.LookAhead(0)==TOK_DEFAULT) // C++0x
{
if(!ansi_c_parser.cpp11)
{
SyntaxError();
return false;
}

lex.get_token(tk);
declarator.value()=codet(ID_default);
set_location(declarator.value(), tk);
}
else if(lex.LookAhead(0)==TOK_DELETE) // C++0x
{
if(!ansi_c_parser.cpp11)
{
SyntaxError();
return false;
}

lex.get_token(tk);
declarator.value()=codet(ID_cpp_delete);
set_location(declarator.value(), tk);
Expand Down

0 comments on commit fafe4d9

Please sign in to comment.