Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
80b29270
Commit
80b29270
authored
8 years ago
by
Vijay Pai
Browse files
Options
Downloads
Patches
Plain Diff
Stop supporting non-C++11 conformant compilers
parent
9dd2c7da
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/cpp-style-guide.md
+3
-85
3 additions, 85 deletions
doc/cpp-style-guide.md
include/grpc++/impl/codegen/config.h
+0
-80
0 additions, 80 deletions
include/grpc++/impl/codegen/config.h
with
3 additions
and
165 deletions
doc/cpp-style-guide.md
+
3
−
85
View file @
80b29270
GRPC C++ STYLE GUIDE
GRPC C++ STYLE GUIDE
=====================
=====================
Background
The majority of gRPC's C++ requirements are drawn from the [Google C++ style
----------
guide] (https://google.github.io/styleguide/cppguide.html). Additionally,
as in C, layout rules are defined by clang-format, and all code
Here we document style rules for C++ usage in the gRPC C++ bindings
and tests.
General
-------
-
The majority of gRPC's C++ requirements are drawn from the [Google C++ style
guide] (https://google.github.io/styleguide/cppguide.html)
-
However, gRPC has some additional requirements to maintain
[portability] (#portability)
-
As in C, layout rules are defined by clang-format, and all code
should be passed through clang-format. A (docker-based) script to do
should be passed through clang-format. A (docker-based) script to do
so is included in [tools/distrib/clang
\_
format
\_
code.sh]
so is included in [tools/distrib/clang
\_
format
\_
code.sh]
(../tools/distrib/clang_format_code.sh).
(../tools/distrib/clang_format_code.sh).
<a
name=
"portability"
></a>
Portability Restrictions
-------------------
gRPC supports a large number of compilers, ranging from those that are
missing many key C++11 features to those that have quite detailed
analysis. As a result, gRPC compiles with a high level of warnings and
treat all warnings as errors. gRPC also forbids the use of some common
C++11 constructs. Here are some guidelines, to be extended as needed:
-
Do not use range-based for. Expressions of the form
```
c
for
(
auto
&
i
:
vec
)
{
// code
}
```
are not allowed and should be replaced with code such as
```
c
for
(
auto
it
=
vec
.
begin
;
it
!=
vec
.
end
();
it
++
)
{
auto
&
i
=
*
it
;
// code
}
```
-
Do not use lambda of any kind (no capture, explicit capture, or
default capture). Other C++ functional features such as
`std::function`
or
`std::bind`
are allowed
-
Do not use brace-list initializers.
-
Do not compare a pointer to
`nullptr`
. This is because gcc 4.4
does not support
`nullptr`
directly and gRPC implements a subset of
its features in [include/grpc++/impl/codegen/config.h]
(../include/grpc++/impl/codegen/config.h). Instead, pointers should
be checked for validity using their implicit conversion to
`bool`
.
In other words, use
`if (p)`
rather than
`if (p != nullptr)`
-
Do not initialize global/static pointer variables to
`nullptr`
. Just let
the compiler implicitly initialize them to
`nullptr`
(which it will
definitely do). The reason is that
`nullptr`
is an actual object in
our implementation rather than just a constant pointer value, so
static/global constructors will be called in a potentially
undesirable sequence.
-
Do not use
`final`
or
`override`
as these are not supported by some
compilers. Instead use
`GRPC_FINAL`
and
`GRPC_OVERRIDE`
. These
compile down to the traditional C++ forms for compilers that support
them but are just elided if the compiler does not support those features.
-
In the [include] (../../../tree/master/include/grpc++) and [src]
(../../../tree/master/src/cpp) directory trees, you should also not
use certain STL objects like
`std::mutex`
,
`std::lock_guard`
,
`std::unique_lock`
,
`std::nullptr`
,
`std::thread`
. Instead, use
`grpc::mutex`
,
`grpc::lock_guard`
, etc., which are gRPC
implementations of the prominent features of these objects that are
not always available. You can use the
`std`
versions of those in [test]
(../../../tree/master/test/cpp)
-
Similarly, in the same directories, do not use
`std::chrono`
unless
it is guarded by
`#ifndef GRPC_CXX0X_NO_CHRONO`
. For platforms that
lack
`std::chrono,`
there is a C-language timer called gpr_timespec that can
be used instead.
-
`std::unique_ptr`
must be used with extreme care in any kind of
collection. For example
`vector<std::unique_ptr>`
does not work in
gcc 4.4 if the vector is constructed to its full size at
initialization but does work if elements are added to the vector
using functions like
`push_back`
.
`map`
and other pair-based
collections do not work with
`unique_ptr`
under gcc 4.4. The issue
is that many of these collection implementations assume a copy
constructor
to be available.
-
Don't use
`std::this_thread`
. Use
`gpr_sleep_until`
for sleeping a thread.
-
[Some adjacent character combinations cause problems]
(https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C). If declaring a
template against some class relative to the global namespace,
`<::name`
will be non-portable. Separate the
`<`
from the
`:`
and use
`< ::name`
.
This diff is collapsed.
Click to expand it.
include/grpc++/impl/codegen/config.h
+
0
−
80
View file @
80b29270
...
@@ -34,79 +34,8 @@
...
@@ -34,79 +34,8 @@
#ifndef GRPCXX_IMPL_CODEGEN_CONFIG_H
#ifndef GRPCXX_IMPL_CODEGEN_CONFIG_H
#define GRPCXX_IMPL_CODEGEN_CONFIG_H
#define GRPCXX_IMPL_CODEGEN_CONFIG_H
#if !defined(GRPC_NO_AUTODETECT_PLATFORM)
#ifdef _MSC_VER
// Visual Studio 2010 is 1600.
#if _MSC_VER < 1600
#error "gRPC is only supported with Visual Studio starting at 2010"
// Visual Studio 2013 is 1800.
#elif _MSC_VER < 1800
#define GRPC_CXX0X_NO_FINAL 1
#define GRPC_CXX0X_NO_OVERRIDE 1
#define GRPC_CXX0X_NO_CHRONO 1
#define GRPC_CXX0X_NO_THREAD 1
#endif
#endif // Visual Studio
#ifndef __clang__
#ifdef __GNUC__
// nullptr was added in gcc 4.6
#if (__GNUC__ * 100 + __GNUC_MINOR__ < 406)
#define GRPC_CXX0X_NO_NULLPTR 1
#define GRPC_CXX0X_LIMITED_TOSTRING 1
#endif
// final and override were added in gcc 4.7
#if (__GNUC__ * 100 + __GNUC_MINOR__ < 407)
#define GRPC_CXX0X_NO_FINAL 1
#define GRPC_CXX0X_NO_OVERRIDE 1
#endif
#endif
#endif
#endif
#ifdef GRPC_CXX0X_NO_FINAL
#define GRPC_FINAL
#else
#define GRPC_FINAL final
#define GRPC_FINAL final
#endif
#ifdef GRPC_CXX0X_NO_OVERRIDE
#define GRPC_OVERRIDE
#else
#define GRPC_OVERRIDE override
#define GRPC_OVERRIDE override
#endif
#ifdef GRPC_CXX0X_NO_NULLPTR
#include
<functional>
#include
<memory>
namespace
grpc
{
const
class
{
public:
template
<
class
T
>
operator
T
*
()
const
{
return
static_cast
<
T
*>
(
0
);
}
template
<
class
T
>
operator
std
::
unique_ptr
<
T
>
()
const
{
return
std
::
unique_ptr
<
T
>
(
static_cast
<
T
*>
(
0
));
}
template
<
class
T
>
operator
std
::
shared_ptr
<
T
>
()
const
{
return
std
::
shared_ptr
<
T
>
(
static_cast
<
T
*>
(
0
));
}
operator
bool
()
const
{
return
false
;
}
template
<
class
F
>
operator
std
::
function
<
F
>
()
const
{
return
std
::
function
<
F
>
();
}
private
:
void
operator
&
()
const
=
delete
;
}
nullptr
=
{};
}
#endif
#ifndef GRPC_CUSTOM_STRING
#ifndef GRPC_CUSTOM_STRING
#include
<string>
#include
<string>
...
@@ -117,16 +46,7 @@ namespace grpc {
...
@@ -117,16 +46,7 @@ namespace grpc {
typedef
GRPC_CUSTOM_STRING
string
;
typedef
GRPC_CUSTOM_STRING
string
;
#ifdef GRPC_CXX0X_LIMITED_TOSTRING
inline
grpc
::
string
to_string
(
const
int
x
)
{
return
std
::
to_string
(
static_cast
<
const
long
long
int
>
(
x
));
}
inline
grpc
::
string
to_string
(
const
unsigned
int
x
)
{
return
std
::
to_string
(
static_cast
<
const
long
long
unsigned
int
>
(
x
));
}
#else
using
std
::
to_string
;
using
std
::
to_string
;
#endif
}
// namespace grpc
}
// namespace grpc
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment