summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Lykke Andersen <jakobandersen@users.noreply.github.com>2021-04-18 17:02:59 +0200
committerGitHub <noreply@github.com>2021-04-18 17:02:59 +0200
commit9105635389e917804897e743fa639cbcbb394453 (patch)
tree9dba5683e648cf1569bf4285429c218d6fab3e86
parent8ec937d4c965b0abd4c2c77d139a884455f907ae (diff)
parent025ec263f9f03c27f7ef2ade4b5b1d7a8f42fcac (diff)
downloadsphinx-git-9105635389e917804897e743fa639cbcbb394453.tar.gz
Merge pull request #9113 from jakobandersen/c_cpp_alias_fix
C, C++, alias fix
-rw-r--r--CHANGES3
-rw-r--r--sphinx/domains/c.py3
-rw-r--r--sphinx/domains/cpp.py3
3 files changed, 7 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index bb776bcc8..929638388 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,9 @@ Features added
Bugs fixed
----------
+* C, C++, fix ``KeyError`` when an ``alias`` directive is the first C/C++
+ directive in a file with another C/C++ directive later.
+
Testing
--------
diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py
index 1eeaf65cf..b0711f68e 100644
--- a/sphinx/domains/c.py
+++ b/sphinx/domains/c.py
@@ -3454,7 +3454,8 @@ class AliasNode(nodes.Element):
if 'c:parent_symbol' not in env.temp_data:
root = env.domaindata['c']['root_symbol']
env.temp_data['c:parent_symbol'] = root
- self.parentKey = env.temp_data['c:parent_symbol'].get_lookup_key()
+ env.ref_context['c:parent_key'] = root.get_lookup_key()
+ self.parentKey = env.ref_context['c:parent_key']
else:
assert parentKey is not None
self.parentKey = parentKey
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index 4a36f6131..d57c6e257 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -7177,7 +7177,8 @@ class AliasNode(nodes.Element):
if 'cpp:parent_symbol' not in env.temp_data:
root = env.domaindata['cpp']['root_symbol']
env.temp_data['cpp:parent_symbol'] = root
- self.parentKey = env.temp_data['cpp:parent_symbol'].get_lookup_key()
+ env.ref_context['cpp:parent_key'] = root.get_lookup_key()
+ self.parentKey = env.ref_context['cpp:parent_key']
else:
assert parentKey is not None
self.parentKey = parentKey