Skip to content
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

Add heuristics for C++ macros #6715

Merged
merged 3 commits into from
Mar 8, 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
1 change: 1 addition & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ named_patterns:
- '^[ \t]*catch\s*\('
- '^[ \t]*(class|(using[ \t]+)?namespace)\s+\w+'
- '^[ \t]*(private|public|protected):$'
- '__has_cpp_attribute|__cplusplus >'
- 'std::\w+'
euphoria:
- '^\s*namespace\s'
Expand Down
24 changes: 24 additions & 0 deletions samples/C++/NoDiscard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===--- NoDiscard.h ------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_BASIC_NODISCARD_H
#define SWIFT_BASIC_NODISCARD_H

#if __cplusplus > 201402l && __has_cpp_attribute(nodiscard)
#define SWIFT_NODISCARD [[nodiscard]]
#elif __has_cpp_attribute(clang::warn_unused_result)
#define SWIFT_NODISCARD [[clang::warn_unused_result]]
#else
#define SWIFT_NODISCARD
#endif

#endif
2 changes: 1 addition & 1 deletion test/test_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_vendored

def test_language
allowed_failures = {
"#{samples_path}/C++/rpc.h" => ["C", "C++"],
"#{samples_path}/C/rpc.h" => ["C", "C++"],
}
Samples.each do |sample|
blob = sample_blob_memory(sample[:path])
Expand Down
2 changes: 1 addition & 1 deletion test/test_classifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_instance_classify_nil
def test_classify_ambiguous_languages
# Failures are reasonable in some cases, such as when a file is fully valid in more than one language.
allowed_failures = {
"#{samples_path}/C++/rpc.h" => ["C", "C++"],
"#{samples_path}/C/rpc.h" => ["C", "C++"],
}

# Skip extensions with catch-all rule
Expand Down
2 changes: 1 addition & 1 deletion test/test_file_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def test_documentation
def test_language
# Failures are reasonable in some cases, such as when a file is fully valid in more than one language.
allowed_failures = {
"#{samples_path}/C++/rpc.h" => ["C", "C++"],
"#{samples_path}/C/rpc.h" => ["C", "C++"],
}
Samples.each do |sample|
blob = sample_blob(sample[:path])
Expand Down
Loading