Skip to content

Commit

Permalink
Merge pull request google#1107 from google/reject-anon-namespace-type…
Browse files Browse the repository at this point in the history
…defs

Reject typedefs to anon namespaces.
  • Loading branch information
adetaylor authored May 19, 2022
2 parents 070c975 + c118dba commit f9b24b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions engine/src/conversion/analysis/type_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ impl<'a> TypeConverter<'a> {
if encountered.contains(&new_tn) {
return Err(ConvertError::InfinitelyRecursiveTypedef(tn.clone()));
}
if typ
.path
.segments
.iter()
.any(|seg| seg.ident.to_string().starts_with("_bindgen_mod"))
{
return Err(ConvertError::TypedefToTypeInAnonymousNamespace);
}
encountered.insert(new_tn.clone());
tn = new_tn;
}
Expand Down
2 changes: 2 additions & 0 deletions engine/src/conversion/convert_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub enum ConvertError {
ConcreteVersionOfIgnoredTemplate,
#[error("bindgen decided to call this type _bindgen_ty_N because it couldn't deduce the correct name for it. That means we can't generate C++ bindings to it.")]
BindgenTy,
#[error("This is a typedef to a type in an anonymous namespace, not currently supported.")]
TypedefToTypeInAnonymousNamespace,
#[error("This type refers to a generic type parameter of an outer type, which is not yet supported.")]
ReferringToGenericTypeParam,
#[error("This forward declaration was nested within another struct/class. autocxx is unable to represent inner types if they are forward declarations.")]
Expand Down
4 changes: 1 addition & 3 deletions integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11207,9 +11207,7 @@ fn test_issue_1098b() {
run_generate_all_test(hdr);
}

/// Need to reject typedefs within anonymous namespaces.
#[test]
#[ignore] // https://github.com/google/autocxx/pull/1098
fn test_issue_1098c() {
let hdr = indoc! {"
namespace {
Expand All @@ -11220,7 +11218,7 @@ fn test_issue_1098c() {
typedef A B;
} // namespace
} // namespace
inline void take_b(const B& b) {}
inline void take_b(const B&) {}
"};
run_generate_all_test(hdr);
}
Expand Down

0 comments on commit f9b24b9

Please sign in to comment.