Skip to content

CBMC C++ frontend doesn't support namespace attributes #2358

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

Closed
smowton opened this issue Jun 15, 2018 · 7 comments
Closed

CBMC C++ frontend doesn't support namespace attributes #2358

smowton opened this issue Jun 15, 2018 · 7 comments
Assignees

Comments

@smowton
Copy link
Contributor

smowton commented Jun 15, 2018

Excerpt from glibc 2.27:

namespace std
{
  inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
}

The CBMC frontend however can't parse such a thing, as it doesn't expect attributes on namespaces. This causes tests that include <cassert> among other headers to fail.

A change such as the following successfully hacks around the problem:

--- a/src/cpp/parse.cpp
+++ b/src/cpp/parse.cpp
@@ -856,6 +856,16 @@ bool Parser::rNamespaceSpec(cpp_namespace_spect &namespace_spec)
   namespace_spec.set_namespace(name);
   namespace_spec.set_is_inline(is_inline);
 
+  if(lex.LookAhead(0)==TOK_GCC_ATTRIBUTE)
+  {
+    cpp_tokent tk;
+    lex.get_token(tk);
+
+    typet discard;
+    if(!rAttribute(discard))
+      return false;
+  }
+
   switch(lex.LookAhead(0))
   {
   case '{':

However I don't know enough about either the C++ grammar to say whether the attribute can occur in other places, or about the parser's structure to know whether a simple throw-away like that is sufficient.

@tautschnig
Copy link
Collaborator

I'd much encourage you to create a PR with exactly this patch! The current C++ front-end is in a best-effort state, so we'll notice when we need more than the above patch when new tests come up!

@smowton
Copy link
Contributor Author

smowton commented Jun 15, 2018

#2360

@smowton
Copy link
Contributor Author

smowton commented Jun 15, 2018

The C++ standard one is trickier -- want to always pass -std=c++03 to the preprocessor if we're not told otherwise?

@tautschnig
Copy link
Collaborator

Really #2360 (Java instanceof)?

@tautschnig
Copy link
Collaborator

Yes, we should always pass some -std - I'm however leaning towards -std=c++98.

@smowton
Copy link
Contributor Author

smowton commented Jun 18, 2018

Oops. #2362

@tautschnig
Copy link
Collaborator

Fixed via #2362.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants