@@ -41,14 +41,28 @@ impl CFamilyCompilationEntry {
4141 }
4242 let standards: Vec < _ > = args
4343 . iter ( )
44- . filter ( |a| a. starts_with ( "-std" ) || a. starts_with ( "--std" ) )
44+ . filter ( |a| {
45+ matches ! ( a. as_str( ) , "-std" | "--std" )
46+ || a. starts_with ( "-std=" )
47+ || a. starts_with ( "--std=" )
48+ } )
4549 . collect ( ) ;
4650 if standards. len ( ) > 1 {
4751 return Some ( "compilation_database_standard_ambiguous" ) ;
4852 }
4953 match standards. first ( ) . map ( |a| a. as_str ( ) ) {
5054 None => Some ( "compilation_database_standard_missing" ) ,
51- Some ( "-std=c11" | "-std=c++17" ) => None ,
55+ Some ( "-std=c11" | "-std=c++17" | "--std=c11" | "--std=c++17" ) => None ,
56+ Some ( "--std" ) => {
57+ let index = args
58+ . iter ( )
59+ . position ( |a| a == "--std" )
60+ . expect ( "已匹配原参数" ) ;
61+ match args. get ( index + 1 ) . map ( String :: as_str) {
62+ Some ( "c11" | "c++17" ) => None ,
63+ _ => Some ( "compilation_database_standard_unsupported" ) ,
64+ }
65+ }
5266 Some ( _) => Some ( "compilation_database_standard_unsupported" ) ,
5367 }
5468 }
@@ -144,6 +158,22 @@ mod tests {
144158 assert_eq ! ( entries[ 0 ] . execution_context_blocker( ) , None ) ;
145159 }
146160
161+ #[ test]
162+ fn standard_library_selection_is_not_a_language_standard_conflict ( ) {
163+ for arguments in [
164+ vec ! [ "clang++" , "-std=c++17" , "-stdlib=libc++" , "file.cpp" ] ,
165+ vec ! [ "clang++" , "--std=c++17" , "file.cpp" ] ,
166+ vec ! [ "clang++" , "--std" , "c++17" , "file.cpp" ] ,
167+ vec ! [ "clang++" , "-stdlib=libstdc++" , "-std=c++17" , "file.cpp" ] ,
168+ ] {
169+ let input =
170+ serde_json:: json!( [ { "directory" : "/build" , "file" : "file.cpp" , "arguments" : arguments} ] ) ;
171+ let entries =
172+ parse_c_family_compilation_database ( & serde_json:: to_vec ( & input) . unwrap ( ) ) . unwrap ( ) ;
173+ assert_eq ! ( entries[ 0 ] . execution_context_blocker( ) , None ) ;
174+ }
175+ }
176+
147177 #[ test]
148178 fn malformed_or_command_only_entries_never_become_clean_scope ( ) {
149179 for bytes in [
0 commit comments