Skip to content

C++ front-end: permit GCC attributes in using declarations #8286

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

Merged
merged 1 commit into from
May 11, 2024
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
13 changes: 13 additions & 0 deletions regression/cpp/using1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifdef __GNUC__
using type __attribute__((__nodebug__)) = int;

typedef int my_int_t;
namespace N
{
using ::my_int_t __attribute__((__using_if_exists__));
}
#endif

int main(int argc, char *argv[])
{
}
8 changes: 8 additions & 0 deletions regression/cpp/using1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.cpp
-std=c++11
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
51 changes: 37 additions & 14 deletions src/cpp/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
bool rLinkageSpec(cpp_linkage_spect &);
bool rNamespaceSpec(cpp_namespace_spect &);
bool rUsing(cpp_usingt &);
bool rUsingOrTypedef(cpp_itemt &);
bool rStaticAssert(cpp_static_assertt &);
bool rLinkageBody(cpp_linkage_spect::itemst &);
bool rTemplateDecl(cpp_declarationt &);
Expand Down Expand Up @@ -581,14 +582,8 @@
return rNamespaceSpec(item.make_namespace_spec());
else if(t==TOK_INLINE && lex.LookAhead(1)==TOK_NAMESPACE)
return rNamespaceSpec(item.make_namespace_spec());
else if(
t == TOK_USING && is_identifier(lex.LookAhead(1)) &&
lex.LookAhead(2) == '=')
{
return rTypedefUsing(item.make_declaration());
}
else if(t==TOK_USING)
return rUsing(item.make_using());
return rUsingOrTypedef(item);
else if(t==TOK_STATIC_ASSERT)
return rStaticAssert(item.make_static_assert());
else
Expand Down Expand Up @@ -668,6 +663,9 @@
std::cout << std::string(__indent, ' ') << "Parser::rTypedefUsing 2\n";
#endif

if(!optAttribute(declaration.type()))
return false;

if(lex.get_token(tk)!='=')
return false;

Expand Down Expand Up @@ -901,12 +899,43 @@
if(!rName(cpp_using.name()))
return false;

// We will eventually need to record this attribute as Clang's
// __using_if_exists__ affects type checking.
typet discard;
if(!optAttribute(discard))
return false;

if(lex.get_token(tk)!=';')
return false;

return true;
}

/*
USING Identifier '=' type.specifier ';'

Check warning on line 915 in src/cpp/parse.cpp

View check run for this annotation

Codecov / codecov/patch

src/cpp/parse.cpp#L915

Added line #L915 was not covered by tests
| using.declaration
*/

Check warning on line 917 in src/cpp/parse.cpp

View check run for this annotation

Codecov / codecov/patch

src/cpp/parse.cpp#L917

Added line #L917 was not covered by tests
bool Parser::rUsingOrTypedef(cpp_itemt &item)
{
cpp_token_buffert::post pos = lex.Save();

cpp_tokent tk;
if(lex.get_token(tk) != TOK_USING)
return false;

typet discard;
if(
is_identifier(lex.get_token(tk)) && optAttribute(discard) &&
lex.LookAhead(0) == '=')
{
lex.Restore(pos);
return rTypedefUsing(item.make_declaration());
}

lex.Restore(pos);
return rUsing(item.make_using());
}

/*
static_assert.declaration : STATIC_ASSERT ( expression , expression ) ';'
*/
Expand Down Expand Up @@ -4731,14 +4760,8 @@
return rTypedef(member.make_declaration());
else if(t==TOK_TEMPLATE)
return rTemplateDecl(member.make_declaration());
else if(
t == TOK_USING && is_identifier(lex.LookAhead(1)) &&
lex.LookAhead(2) == '=')
{
return rTypedefUsing(member.make_declaration());
}
else if(t==TOK_USING)
return rUsing(member.make_using());
return rUsingOrTypedef(member);

Check warning on line 4764 in src/cpp/parse.cpp

View check run for this annotation

Codecov / codecov/patch

src/cpp/parse.cpp#L4764

Added line #L4764 was not covered by tests
else if(t==TOK_STATIC_ASSERT)
return rStaticAssert(member.make_static_assert());
else
Expand Down
Loading