Skip to content

Commit e85d2a7

Browse files
Minor update to C++ guidelines (#8184)
1 parent f004895 commit e85d2a7

2 files changed

Lines changed: 45 additions & 41 deletions

File tree

docs/cpp/implementation.md

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Note that modifying the enumerators in an enumeration is considered a breaking c
7878

7979
##### Extendable Enumerations
8080

81-
When the set of values in an enumeration is *not* fixed, the `Azure::Core::_internal::ExtendableEnumeration` template should be used.
81+
When the set of values in an enumeration is *not* fixed, the `Azure::Core::_internal::ExtendableEnumeration` template should be used.
8282

8383
{% highlight cpp %}
8484
class MyEnumeration final : public ExtendableEnumeration<MyEnumeration> {
@@ -107,6 +107,7 @@ Subtypes of `Operation<T>` are returned from service client methods invoking lon
107107

108108
- If an underlying service operation call from `Poll` or `PollUntilDone` throws, re-throw `RequestFailedException` or its subtype.
109109
- If the operation completes with a non-success result, throw `RequestFailedException` or its subtype from `Poll` or `PollUntilDone`.
110+
110111
- Include any relevant error state information in the exception message.
111112

112113
- If the ```Value``` property is evaluated after the operation failed (```HasValue``` is false and ```IsDone``` is true) throw the same exception as the one thrown when the operation failed.
@@ -262,7 +263,7 @@ We believe testing is a part of the development process, so we expect unit and i
262263

263264
All code should contain, at least, requirements, unit tests, end-to-end tests, and samples.
264265

265-
Tests should be written using the [Google Test][] library.
266+
Tests should be written using the [Google Test][https://google.github.io/googletest/] library.
266267

267268
### Language-specific other
268269

@@ -336,6 +337,7 @@ void Example()
336337
#endif
337338

338339
more code
340+
339341
}
340342
{% endhighlight %}
341343

@@ -387,8 +389,7 @@ else { HappyDaysIKnowWhyIAmHere(); }
387389

388390
{% include requirement/SHOULD id="cpp-use-cpp-core-guidelines" %} follow the [CPP Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md) whenever possible, with the following exceptions:
389391

390-
<TBD>
391-
392+
- List TBD.
392393

393394
#### Complexity Management
394395

@@ -403,6 +404,8 @@ not escape from the innermost lexical scope.
403404

404405
{% include requirement/MUST id="cpp-use-explicit-compares" %} use explicit comparisons when testing for failure. Use `if (FAIL != f())` rather than `if (f())`, even though FAIL may have the value 0 which C considers to be false. An explicit test will help you out later when somebody decides that a failure return should be -1 instead of 0.
405406

407+
{% include requirement/MUSTNOT id="cpp-do-not-compare-booleans-against-true" %} compare boolean values with explicit comparisons. Rather than writing `if (f() == true)`, write `if (f())` - the result is clearer and more succinct. The same applies to objects that implement `operator bool()`
408+
406409
Explicit comparison should be used even if the comparison value will never change. e.g. `if (!(bufsize % sizeof(int)))` should be written as `if (0 == (bufsize % sizeof(int))` to reflect the numeric (not boolean) nature of the test.
407410

408411
A frequent trouble spot is using `strcmp` to test for string equality. You should **never** use a default action. The preferred approach is to use an inline function:
@@ -414,6 +417,7 @@ inline bool StringEqual(char *a, char *b) {
414417
{% endhighlight %}
415418

416419
~ Should
420+
417421
{% include requirement/SHOULDNOT id="cpp-embedded-assign" %} use embedded assignments. There is a time and a place for embedded assignment statements. In some constructs, there is no better way to accomplish the results without making the code bulkier and less readable.
418422

419423
{% highlight cpp %}
@@ -498,7 +502,6 @@ void TheCustomerCode() {
498502
}
499503
{% endhighlight %}
500504

501-
502505
{% include requirement/MUST id="cpp-design-logical-no-getters-or-setters" %} define getters and setters for data transfer objects. Expose the members directly to users unless you need to enforce some constraints on the data. For example:
503506
{% highlight cpp %}
504507
// Good - no restrictions on values
@@ -535,7 +538,7 @@ public:
535538
return m_size;
536539
}
537540
void AddData(int i) noexcept {
538-
m_data\[m_size++\] = i;
541+
m_data[m_size++] = i;
539542
}
540543
};
541544

@@ -560,7 +563,7 @@ public:
560563
{% highlight cpp %}
561564
// Bad
562565
struct Foo {
563-
int A; // the compiler will insert 4 bytes of padding after A to align B
566+
int A; // the compiler will insert up to 4 bytes of padding after A to align B
564567
char *B;
565568
int C;
566569
char *D;
@@ -605,6 +608,10 @@ public:
605608
};
606609
{% endhighlight %}
607610

611+
#### Parameter passing rules
612+
613+
In general, all method parameters that are not POD should be passed by `const reference`.
614+
608615
#### Integer sizes
609616

610617
The following integer rules are listed in rough priority order. Integer size selections are primarily driven by service future compatibility. For example, just because today a service might have a 2 GiB file size limit does not mean that it will have such a limit forever. We believe 64 bit length limits will be sufficient for sizes an individual program works with for the foreseeable future.
@@ -661,6 +668,7 @@ public:
661668
const static KeyType Rsa;
662669
const static KeyType RsaHsm;
663670
const static KeyType Oct;
671+
664672
};
665673
}}} // namespace Azure::Group::Service
666674

@@ -835,13 +843,14 @@ set(DOXYGEN_SIMPLE_STRUCTS YES)
835843
set(DOXYGEN_TYPEDEF_HIDES_STRUCT NO)
836844

837845
doxygen_add_docs(doxygen
838-
${PROJECT_SOURCE_DIR}/inc
839-
${PROJECT_SOURCE_DIR}/src
840-
${PROJECT_SOURCE_DIR}/doc
841-
COMMENT "generate docs")
846+
${PROJECT_SOURCE_DIR}/inc
847+
${PROJECT_SOURCE_DIR}/src
848+
${PROJECT_SOURCE_DIR}/doc
849+
COMMENT "generate docs")
842850
{% endhighlight %}
843851

844852
Notice that:
853+
845854
* We use `find_package()` to find doxygen
846855
* We use the `DOXYGEN_<PREF>` CMake variables instead of writing your own `doxyfile`.
847856
* We set `OPTIMIZE_OUTPUT_FOR_C` in order to get more C appropriate output.
@@ -859,39 +868,27 @@ endif()
859868

860869
## Supported platforms
861870

862-
{% include requirement/MUST id="cpp-platform-min" %} support the following platforms and associated compilers when implementing your client library.
863-
864-
### Windows
871+
{% include requirement/MUST id="cpp-platform-min" %} support at least the following platforms and associated compilers when implementing your client library:
865872

866-
| Operating System | Version | Architectures | Compiler Version | Notes
867-
|----------------------|---------------|---------------|-----------------------------------------|------
868-
| Windows Client | 7 SP1+, 8.1 | x64, x86 | MSVC 14.16.x, MSVC 14.20x |
869-
| Windows 10 Client | Version 1607+ | x64, x86, ARM | MSVC 14.16.x, MSVC 14.20x |
870-
| Windows 10 Client | Version 1909+ | ARM64 | MSVC 14.20x |
871-
| Nano Server | Version 1803+ | x64, ARM32 | MSVC 14.16.x, MSVC 14.20x |
872-
| Windows Server | 2012 R2+ | x64, x86 | MSVC 14.16.x, MSVC 14.20x |
873+
- Windows
874+
- Unix-like operating systems (Linux, Unix, etc)
875+
- OSX/iOS
873876

874-
### Mac
877+
As of 10/2024, the Azure SDK for C++ is currently tested against the following platforms:
875878

876-
| Operating System | Version | Architectures | Compiler Version | Notes
877-
|---------------------------------|---------------|---------------|-----------------------------------------|------
878-
| macOS | 10.13+ | x64 | XCode 9.4.1 |
879+
| Operating System | Versions | Architectures| Compiler | Compiler Version | Notes |
880+
|------------------|------------|--------------|----------|-------------------|-------|
881+
| Windows | 2019, 2022 | x32, x64 | MSVC | MSVC 16, MSVC 17 | |
882+
| OSX | 14 | x64 | XCODE | 15.4 | |
883+
| Linux - Ubuntu | 2020.04, 2022.04 | x64 | GCC | 8, 9 | |
884+
| Linux - Ubuntu | 2020.04, 2022.04 | x64 | clang | 11, 13, 15 | |
879885

880-
#### Linux
886+
For a current list of supported platforms, see the [platform matrix](https://github.com/Azure/azure-sdk-for-cpp/blob/main/eng/pipelines/templates/stages/platform-matrix.json).
881887

882-
| Operating System | Version | Architectures | Compiler Version | Notes
883-
|---------------------------------|---------------|---------------|-----------------------------------------|------
884-
| Red Hat Enterprise Linux <br> CentOS <br> Oracle Linux | 7+ | x64 | gcc-4.8 | [Red Hat lifecycle](https://access.redhat.com/support/policy/updates/errata/) <br> [CentOS lifecycle](https://www.centos.org/centos-linux-eol/) <br> [Oracle Linux lifecycle](https://www.oracle.com/us/support/library/elsp-lifetime-069338.pdf)
885-
| Debian | 9+ | x64 | gcc-6.3 | [Debian lifecycle](https://wiki.debian.org/DebianReleases)
886-
| Ubuntu | 18.04, 16.04 | x64 | gcc-7.3 | [Ubuntu lifecycle](https://wiki.ubuntu.com/Releases)
887-
| Linux Mint | 18+ | x64 | gcc-7.3 | [Linux Mint lifecycle](https://www.linuxmint.com/download_all.php)
888-
| openSUSE | 15+ | x64 | gcc-7.5 | [OpenSUSE lifecycle](https://en.opensuse.org/Lifetime)
889-
| SUSE Enterprise Linux (SLES) | 12 SP2+ | x64 | gcc-4.8 | [SUSE lifecycle](https://www.suse.com/lifecycle/)
890888

891889
{% include requirement/SHOULD id="cpp-platform" %} support the following additional platforms and associated compilers when implementing your client library.
892890

893-
894-
{% include requirement/SHOULDNOT id="cpp-cpp-extensions" %} use compiler extensions. Examples of extensions to avoid include:
891+
{% include requirement/SHOULDNOT id="cpp-cpp-extensions" %} use compiler extensions. Examples of extensions to avoid include:
895892

896893
* [MSVC compiler extensions](https://docs.microsoft.com/cpp/build/reference/microsoft-extensions-to-c-and-cpp)
897894
* [clang language extensions](https://clang.llvm.org/docs/LanguageExtensions.html)
@@ -901,8 +898,8 @@ Use the appropriate options for each compiler to prevent the use of such extensi
901898

902899
{% include requirement/MUST id="cpp-cpp-options" %} use compiler flags to identify warnings:
903900

904-
| Compiler | Compiler Flags |
905-
|:-------------------------|------------------|
906-
| gcc | `-Wall -Wextra` |
907-
| cpp and XCode | `-Wall -Wextra` |
908-
| MSVC | `/W4` |
901+
| Compiler | Compiler Flags |
902+
| :------------ | --------------- |
903+
| gcc | `-Wall -Wextra` |
904+
| cpp and XCode | `-Wall -Wextra` |
905+
| MSVC | `/W4` |

docs/cpp/introduction.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ NOTE: Since these types are typically located in the `azure-core` package, care
675675
In addition, it is critical to realize that the only dependencies between Azure SDK packages is a >= dependency. That means that a particular version of an existing Azure SDK package is expected to work with any future versions of other Azure SDK packages, even of those packages on which it depends. That means that any breaking changes to internal types MUST be upward compatible.
676676

677677
##### Private types
678+
678679
Private types are types located in a `_detail` namespace. Private types are only intended to be called within a single package, and follow the following requirements:
679680

680681
{% include requirement/MUSTNOT id="cpp-design-private-types-private" %} define private types in public Azure SDK headers.
@@ -840,6 +841,12 @@ Filenames should be concise, but convey what role the file plays within the libr
840841
- `<package short name>/` - eg `certificates`, `blobs`, `datalake`, etc.
841842
- `<package specific headers>`
842843

844+
{% include requirement/MUST id="cpp-client-name" %} base the file name for the service client on the name of the service client.
845+
846+
For example, the class declaration for the `AttestationClient` class should be contained in a file named `attestation_client.hpp`.
847+
848+
{% include requirement/SHOULD id="cpp-docs-file-contents-exception" %} have at most one service client declaration per include file.
849+
843850
{% include requirement/MUST id="cpp-docs-source-layout-src" %} lay out directories under the `src` directory as follows:
844851

845852
- `src/`

0 commit comments

Comments
 (0)