Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ front-end: support =delete method declarations #2340

Merged
merged 6 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions regression/cbmc-cpp/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
default: tests.log

test:
@../test.pl -c ../../../src/cbmc/cbmc
@../test.pl -p -c ../../../src/cbmc/cbmc

tests.log: ../test.pl
@../test.pl -c ../../../src/cbmc/cbmc
@../test.pl -p -c ../../../src/cbmc/cbmc

show:
@for dir in *; do \
Expand Down
1 change: 1 addition & 0 deletions regression/cbmc-cpp/MethodParam1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
unsigned x;

class ct {
public:
void f(int i) {
x=x+i;
}
Expand Down
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
14 changes: 12 additions & 2 deletions src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,18 @@ and { return cpp98_keyword(TOK_ANDAND); }
and_eq { return cpp98_keyword(TOK_ANDASSIGN); }
bool { return cpp98_keyword(TOK_BOOL); }
catch { return cpp98_keyword(TOK_CATCH); }
char16_t { return cpp11_keyword(TOK_CHAR16_T); } // C++11
char32_t { return cpp11_keyword(TOK_CHAR32_T); } // C++11
char16_t { // C++11, but Visual Studio uses typedefs
if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
return make_identifier();
else
return cpp11_keyword(TOK_CHAR16_T);
}
char32_t { // C++11, but Visual Studio uses typedefs
if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
return make_identifier();
else
return cpp11_keyword(TOK_CHAR32_T);
}
class { return cpp98_keyword(TOK_CLASS); }
compl { return cpp98_keyword('~'); }
constexpr { return cpp11_keyword(TOK_CONSTEXPR); } // C++11
Expand Down
22 changes: 13 additions & 9 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 Expand Up @@ -1487,13 +1495,11 @@ bool cpp_typecheckt::get_component(
}
else
{
#if 0
error().source_location=source_location;
str << "error: member `" << component_name
<< "' is not accessible (" << component.get(ID_access) << ")";
str << "\nstruct name: " << final_type.get(ID_name);
error() << "error: member `" << component_name
<< "' is not accessible (" << component.get(ID_access) << ")"
<< eom;
throw 0;
#endif
}
}

Expand Down Expand Up @@ -1523,12 +1529,10 @@ bool cpp_typecheckt::get_component(
{
if(check_component_access(component, final_type))
{
#if 0
error().source_location=source_location;
str << "error: member `" << component_name
<< "' is not accessible";
error() << "error: member `" << component_name
<< "' is not accessible" << eom;
throw 0;
#endif
}

if(object.get_bool(ID_C_lvalue))
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
4 changes: 4 additions & 0 deletions src/util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,11 @@ configt::cppt::cpp_standardt configt::cppt::default_cpp_standard()
// g++ 6.3 uses gnu++14
// g++ 5.4 uses gnu++98
// clang 6.0 uses c++14
#if defined _WIN32
return cpp_standardt::CPP14;
#else
return cpp_standardt::CPP98;
#endif
}

void configt::set_arch(const irep_idt &arch)
Expand Down