# warning when using caption with hyperref's localanchorname option

The MWE below gives a warning: "warning (pdf backend): ignoring duplicate destination with the name 'section.1'". The warning disappears when commenting out either the option "localanchorname" or \usepackage{caption}. Can this warning be eliminated (not silenced) while keeping both?

\documentclass{article}
\PassOptionsToPackage{%
localanchorname%
}{hyperref}

\usepackage{caption}
\usepackage{hyperref}

\begin{document}
xxx

\begin{figure}
\end{figure}

\end{document}


Basically caption is not compatible to the localanchorname option as it sets the destination name in a group.

I don't think that the option is very useful, it is much better to put the label where it belongs, but if you need it you will have to reset the destination after the group:

\documentclass{article}
\PassOptionsToPackage{%
localanchorname%
}{hyperref}

\usepackage{caption}
\makeatletter
\AtBeginDocument{%
\renewcommand*\caption@makestart[1]{%
\begingroup
\Hy@hypertexnamesfalse
\hyper@makecurrent{#1.caption}%
\global\let\my@currentHref\HyperGlobalCurrentHref
\endgroup
\let\@currentHref\my@currentHref
\caption@Debug{hypcap start=\@currentHref}}}%
\makeatother
\usepackage{hyperref}

\begin{document}