tikz: Bug in 'intersections' library when naming paths inside loop?

I draw two circles and name their path inside a \foreach loop. Trying to name intersections of these two paths throws an error unless I name a third path.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
\foreach \s in {+,-} {
\draw [name path={C\s}] (\s1,0) circle (1.5);}
\draw [name path=Ca] (0,1) circle (1.5);    % <- comment line to see error
\path [name intersections={of=C- and C+}];
\draw [dashed] (intersection-1) -- (intersection-2);
\end{tikzpicture}

\end{document}


Without the marked line commented, the error message reads:

Package tikz Error: I do not know the path named C-'. Perhaps you misspelt it. ...\path [name intersections={of={C-} and C+}];


To me, this seems to be a bug. - Or am I doing something wrong?

• Try global name path. For each is act as a group. – Tarass Mar 22 '18 at 9:27
• @Tarass probably suggests \draw [name path global={C\s}] (\s1,0) circle (1.5);. This works. But it also works when you put any path (you do not have to name it) before \path [name intersections={of=C- and C+}];. Strange. – user121799 Mar 22 '18 at 9:41
• @Tarass: Your solution works. The explanation, however, does not fully apply. Otherwise, name intersection should consistently not work outside the loop. – FlorianL Mar 22 '18 at 10:00
• @FlorianL Yes, that's what I wanted to say with my comment. – user121799 Mar 22 '18 at 10:27
• The code in the foreach loop is in a TeX group, so all definitions are local to this group. If you place the uncommented line before the foreach, it does not work nether. That mean that there a something strange happens (bug ?). – Tarass Mar 22 '18 at 11:54

If you insert some draw command between the loop and the intersection command, it will work even without mentionning a name path. It is a curiosity...

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}

\draw [name path=Ca] (0,1) circle (1.5);    % <- comment line to see error

\foreach \s in {+,-} {
\draw [name path global ={C\s}] (\s1,0) circle (1.5);}

% \draw (0,1) circle (1.5) ; % uncomment this line take off the global parameter and it will work to without accessing to the pathes names ...

\path [name intersections ={of=C- and C+}];

\draw [dashed] (intersection-1) -- (intersection-2);

\end{tikzpicture}

\end{document}
`