cpp_parser 0.1.4

A lossless C++ parser over the preprocessed text: the tree every layer above it reads.
Documentation
//! **MSVC extensions** — what `cl.exe` accepts and a Windows project's headers are written with.

mod common;

use common::assert_all_parse;

const CONSTRUCTS: &[(&str, &str)] = &[
    ("__declspec", "__declspec(dllexport) void f();"),
    (
        "__declspec on a class",
        "class __declspec(dllexport) S { };",
    ),
    ("__cdecl", "void __cdecl f();"),
    ("__stdcall", "void __stdcall f();"),
    ("__fastcall", "void __fastcall f();"),
    ("__forceinline", "__forceinline void f();"),
    ("__int64", "__int64 big = 0;"),
    (
        "__int8 and friends",
        "__int8 a = 0; __int16 b = 0; __int32 c = 0;",
    ),
    ("__m128", "__m128 v = { 0 };"),
    (
        "__uuidof",
        "void f(void* p) { auto id = __uuidof(p); (void)id; }",
    ),
    (
        "__super",
        "struct B { void f(); }; struct D : B { void g() { __super::f(); } };",
    ),
    ("a __ptr32 pointer", "void f(int __ptr32* p);"),
];

#[test]
fn every_msvc_extension_parses_without_an_error() {
    assert_all_parse("MSVC", CONSTRUCTS);
}

/// **The MSVC constructs that used to be gaps** — structured exception handling and `__interface`.
///
/// ```text
///   __try { } __except (1) { }     a block and a handler, like `try`/`catch` — the filter is an expression
///   __try { } __finally { }        the other handler, with no filter at all
///   __interface I : IUnknown { };  a class key spelled as an identifier: name, base clause, body
/// ```
///
/// All three are written by every Windows driver and by MSVC's own headers. `__try`, `__except` and `__interface`
/// are identifiers rather than keywords, so each is recognised by its spelling — the reading `catch` already gets.
#[test]
fn the_msvc_gaps_are_named() {
    assert_all_parse(
        "MSVC gaps",
        &[
            ("__try/__except", "void f() { __try { } __except (1) { } }"),
            ("__try/__finally", "void f() { __try { } __finally { } }"),
            (
                "__interface",
                "__interface I : IUnknown { virtual void f() = 0; };",
            ),
        ],
    );
}