Move all operator<< overloads out of the global namespace.#10546
Closed
ezyang wants to merge 1 commit intopytorch:masterfrom
Closed
Move all operator<< overloads out of the global namespace.#10546ezyang wants to merge 1 commit intopytorch:masterfrom
ezyang wants to merge 1 commit intopytorch:masterfrom
Conversation
59db448 to
3c23d35
Compare
3c23d35 to
9a6356f
Compare
9a6356f to
87baa90
Compare
87baa90 to
7a4d744
Compare
…0546) Summary: Pull Request resolved: pytorch#10546 Have you ever written an operator<< overload in the caffe2 namespace in a core Caffe2 header, and then been stunned when some completely unrelated code started breaking? This diff fixes this problem! The problem looks like this: 1. You're building against a really old version of glog (think 0.3.2, or something like that) 2. This version of glog defines operator<< overloads for std containers in the global namespace 3. You add a new overload in your current namespace (e.g., caffe2). Congratulations: this overload is *preferentially* chosen over the global namespace one for all calls to << in that namespace. And since it doesn't actually have std::vector overloads, unrelated Caffe2 code breaks. Newer versions of glog have a fix for this: they have the line: namespace std { using ::operator<<; } in their header. So let's help old versions of glog out and do this ourselves. In our new world order, operator<< overloads defined in the global namespace won't work (unless they're for std containers, which work because of ADL). So this diff also moves all those overloads to the correct namespace. Differential Revision: D9344540 fbshipit-source-id: 2ed9bf24ed1d7e67ba568bceb533c8589e020b31
7a4d744 to
ffd2cce
Compare
soumith
approved these changes
Aug 16, 2018
zdevito
pushed a commit
to zdevito/ATen
that referenced
this pull request
Aug 16, 2018
Summary: Pull Request resolved: pytorch/pytorch#10546 Have you ever written an operator<< overload in the caffe2 namespace in a core Caffe2 header, and then been stunned when some completely unrelated code started breaking? This diff fixes this problem! The problem looks like this: 1. You're building against a really old version of glog (think 0.3.2, or something like that) 2. This version of glog defines operator<< overloads for std containers in the global namespace 3. You add a new overload in your current namespace (e.g., caffe2). Congratulations: this overload is *preferentially* chosen over the global namespace one for all calls to << in that namespace. And since it doesn't actually have std::vector overloads, unrelated Caffe2 code breaks. Newer versions of glog have a fix for this: they have the line: namespace std { using ::operator<<; } in their header. So let's help old versions of glog out and do this ourselves. In our new world order, operator<< overloads defined in the global namespace won't work (unless they're for std containers, which work because of ADL). So this diff also moves all those overloads to the correct namespace. Reviewed By: dzhulgakov Differential Revision: D9344540 fbshipit-source-id: 6246ed50b86312668ebbd7b039fcd1233a3609cf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Have you ever written an operator<< overload in the caffe2 namespace
in a core Caffe2 header, and then been stunned when some completely
unrelated code started breaking? This diff fixes this problem!
The problem looks like this:
or something like that)
in the global namespace
Congratulations: this overload is preferentially chosen over
the global namespace one for all calls to << in that namespace.
And since it doesn't actually have std::vector overloads, unrelated
Caffe2 code breaks.
Newer versions of glog have a fix for this: they have the line:
namespace std { using ::operator<<; }
in their header. So let's help old versions of glog out and do this ourselves.
In our new world order, operator<< overloads defined in the global namespace
won't work (unless they're for std containers, which work because of ADL).
So this diff also moves all those overloads to the correct namespace.
Differential Revision: D9344540